Example #1
3
 protected static function _findItemId($needles)
 {
     // Prepare the reverse lookup array.
     if (self::$lookup === null) {
         self::$lookup = array();
         $component =& JComponentHelper::getComponent('com_xmap');
         $menus =& JApplication::getMenu('site', array());
         $items = $menus->getItems('component_id', $component->id);
         foreach ($items as &$item) {
             if (isset($item->query) && isset($item->query['view'])) {
                 $view = $item->query['view'];
                 if (!isset(self::$lookup[$view])) {
                     self::$lookup[$view] = array();
                 }
                 if (isset($item->query['id'])) {
                     self::$lookup[$view][$item->query['id']] = $item->id;
                 }
             }
         }
     }
     $match = null;
     foreach ($needles as $view => $id) {
         if (isset(self::$lookup[$view])) {
             if (isset(self::$lookup[$view][$id])) {
                 return self::$lookup[$view][$id];
             }
         }
     }
     return null;
 }
 function getItemid($poll_id)
 {
     $component = JComponentHelper::getComponent('com_mijopolls');
     $menus = JApplication::getMenu('site', array());
     if (MijopollsHelper::is15()) {
         $items = $menus->getItems('componentid', $component->id);
     } else {
         $items = $menus->getItems('component_id', $component->id);
     }
     $match = false;
     $item_id = '';
     if (isset($items)) {
         foreach ($items as $item) {
             if (@$item->query['view'] == 'poll' && @$item->query['id'] == $poll_id) {
                 $itemid = $item->id;
                 $match = true;
                 break;
             }
         }
     }
     if ($match) {
         $item_id = '&Itemid=' . $itemid;
     }
     return $item_id;
 }
Example #3
0
 function getExistmenu()
 {
     $component =& JComponentHelper::getComponent('com_hotelguide');
     $menus =& JApplication::getMenu('site', array());
     $items = $menus->getItems('componentid', $component->id);
     if (count($items) > 0) {
         return true;
     }
     return false;
 }
Example #4
0
 function _findItem($needles)
 {
     $component =& JComponentHelper::getComponent('com_k2');
     $menus =& JApplication::getMenu('site', array());
     $items = $menus->getItems('componentid', $component->id);
     $match = null;
     foreach ($needles as $needle => $id) {
         if (count($items)) {
             foreach ($items as $item) {
                 if ($needle == 'user') {
                     if (@$item->query['task'] == $needle && @$item->query['id'] == $id) {
                         $match = $item;
                         break;
                     }
                 } else {
                     if ($needle == 'tag') {
                         if (@$item->query['task'] == $needle && @$item->query['tag'] == $id) {
                             $match = $item;
                             break;
                         }
                     } else {
                         if (@$item->query['view'] == $needle && @$item->query['id'] == $id) {
                             $match = $item;
                             break;
                         }
                         $menuparams = new JParameter($item->params);
                         $catids = $menuparams->get('categories');
                         if (is_array($catids)) {
                             foreach ($catids as $catid) {
                                 if (@$item->query['view'] == $needle && @(int) $catid == $id) {
                                     $match = $item;
                                     break;
                                 }
                             }
                         }
                         /*else{
                         
                         							if ( (@$item->query['view'] == $needle) && (!isset($item->query['task'])) && (@$item->query['view'] == 'itemlist') ) {
                         								$match = $item;
                         							}
                         
                         						}*/
                     }
                 }
             }
         }
         if (isset($match)) {
             break;
         }
     }
     return $match;
 }
 function getObjectLink($id)
 {
     $link = 'index.php?option=com_blog&view=comments&pid=' . $id;
     require_once JPATH_SITE . DS . 'includes' . DS . 'application.php';
     $component = JComponentHelper::getComponent('com_blog');
     $menus = JApplication::getMenu('site');
     $items = $menus->getItems('componentid', $component->id);
     if (count($items)) {
         $link .= "&Itemid=" . $items[0]->id;
     }
     $link = JRoute::_($link);
     return $link;
 }
 function getObjectLink($id)
 {
     require_once JPATH_ROOT . DS . 'components' . DS . 'com_communitypolls' . DS . 'router.php';
     $query = 'SELECT a.id,' . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug' . ' FROM #__jcp_polls AS a' . ' WHERE a.id = ' . $id;
     $db = JFactory::getDBO();
     $db->setQuery($query);
     $row = $db->loadObject();
     $menu = JApplication::getMenu('site');
     $mnuitems = $menu->getItems('link', 'index.php?option=com_communitypolls&controller=polls');
     $itemid = isset($mnuitems[0]) ? '&Itemid=' . $mnuitems[0]->id : '';
     $link = JRoute::_('index.php?option=com_communitypolls&controller=polls&task=viewpoll&id=' . $row->slug . $itemid);
     return $link;
 }
Example #7
0
 function getName()
 {
     $component =& JComponentHelper::getComponent('com_easybook');
     $menus =& JApplication::getMenu('site', array());
     $items = $menus->getItems('componentid', $component->id);
     $match = null;
     foreach ($items as $item) {
         if (@$item->query['view'] == 'easybook') {
             $match = $item->name;
             break;
         }
     }
     return $match;
 }
 function getObjectLink($id)
 {
     $db = JFactory::getDBO();
     $db->setQuery('SELECT alias FROM #__categories WHERE section = "com_weblinks" and id = ' . $id);
     $alias = $db->loadResult();
     $link = 'index.php?option=com_weblinks&view=category&id=' . $id . ':' . $alias;
     require_once JPATH_SITE . DS . 'includes' . DS . 'application.php';
     $component = JComponentHelper::getComponent('com_weblinks');
     $menus = JApplication::getMenu('site');
     $items = $menus->getItems('componentid', $component->id);
     if (count($items)) {
         $link .= "&Itemid=" . $items[0]->id;
     }
     $link = JRoute::_($link);
     return $link;
 }
Example #9
0
 protected static function _findItem($needles)
 {
     $component = JComponentHelper::getComponent('com_ars');
     $menus = JApplication::getMenu('site');
     $items = $menus->getItems('componentid', $component->id);
     $user = JFactory::getUser();
     $access = (int) $user->get('aid');
     foreach ($items as $item) {
         if ($item->published == 1 && $item->access <= $access) {
             if (isset($item->query) && isset($item->query['view'])) {
                 if ($item->query['view'] == 'release') {
                     $params = $item->params instanceof JRegistry ? $item->params : $menus->getParams($item->id);
                     if ($params->get('relid', 0) == $needles['release_id']) {
                         return $item->id;
                     }
                 }
             }
         }
     }
     foreach ($items as $item) {
         if ($item->published == 1 && $item->access <= $access) {
             if (isset($item->query) && isset($item->query['view'])) {
                 if ($item->query['view'] == 'category') {
                     $params = $item->params instanceof JRegistry ? $item->params : $menus->getParams($item->id);
                     print_r($params);
                     if ($params->get('catid', 0) == $needles['category_id']) {
                         return $item->id;
                     }
                 }
             }
         }
     }
     foreach ($items as $item) {
         if ($item->published == 1 && $item->access <= $access) {
             if (isset($item->query) && isset($item->query['view'])) {
                 if ($item->query['view'] == 'browse') {
                     return $item->id;
                 }
             }
         }
     }
     $active = $menus->getActive();
     if ($active) {
         return $active->id;
     }
     return false;
 }
Example #10
0
	private static function _findItem()
	{
		$component =& JComponentHelper::getComponent('com_helpdesk');

		$menus	= &JApplication::getMenu('site', array());
		$items	= $menus->getItems('componentid', $component->id);
		$match = null;

		foreach($items as $item) {
			if ((@$item->query['view'] == 'helpdesk')) {
				$match = $item->id;
				break;
			}
		}
		
		return $match;
	}
Example #11
0
 protected static function _findItem($product_id, $category_id)
 {
     $component = JComponentHelper::getComponent('com_redshop');
     $menus = JApplication::getMenu('site');
     $field = JCOMMENTS_JVERSION == '1.5' ? 'componentid' : 'component_id';
     $items = $menus->getItems($field, $component->id);
     $user = JFactory::getUser();
     $access = (int) $user->get('aid');
     $count = count($items);
     if ($count == 1) {
         return $items[0]->id;
     } else {
         if ($count > 1) {
             foreach ($items as $item) {
                 if ($item->access <= $access) {
                     if (isset($item->query) && isset($item->query['view'])) {
                         if ($item->query['view'] == 'category' && isset($item->query['cid'])) {
                             if ($item->query['cid'] = $category_id) {
                                 return $item->id;
                             }
                         }
                     }
                 }
             }
             $db = JFactory::getDBO();
             $db->setQuery('SELECT category_id FROM #__redshop_product_category_xref WHERE product_id = ' . $product_id);
             $categories = $db->loadResultArray();
             foreach ($items as $item) {
                 if ($item->access <= $access) {
                     if (isset($item->query) && isset($item->query['view'])) {
                         if ($item->query['view'] == 'category' && isset($item->query['cid'])) {
                             if (in_array($item->query['cid'], $categories)) {
                                 return $item->id;
                             }
                         }
                     }
                 }
             }
         }
     }
     $active = $menus->getActive();
     if ($active) {
         return $active->id;
     }
     return false;
 }
 protected static function _findItem($needles)
 {
     $component = JComponentHelper::getComponent('com_docman');
     $menus = JApplication::getMenu('site');
     $items = $menus->getItems('componentid', $component->id);
     $user = JFactory::getUser();
     $access = (int) $user->get('aid');
     foreach ($needles as $needle => $id) {
         if (is_array($items)) {
             foreach ($items as $item) {
                 if ($item->published == 1 && $item->access <= $access) {
                     return $item;
                 }
             }
         }
     }
     return false;
 }
Example #13
0
 function _findItem($needles)
 {
     $component =& JComponentHelper::getComponent('com_content');
     $menus =& JApplication::getMenu('site', array());
     $items = $menus->getItems('componentid', $component->id);
     $match = null;
     foreach ($needles as $needle => $id) {
         foreach ($items as $item) {
             if (@$item->query['view'] == $needle && @$item->query['id'] == $id) {
                 $match = $item;
                 break;
             }
         }
         if (isset($match)) {
             break;
         }
     }
     return $match;
 }
 function getObjectInfo($id, $language = null)
 {
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     $query->select('a.id, a.title, a.alias, a.created_by');
     $query->from('#__jcp_polls AS a');
     $query->where('a.id = ' . (int) $id);
     $db->setQuery($query);
     $row = $db->loadObject();
     $info = new JCommentsObjectInfo();
     if (!empty($row)) {
         $row->slug = $row->alias ? $row->id . ':' . $row->alias : $row->id;
         $items = JApplication::getMenu('site')->getItems('link', 'index.php?option=com_communitypolls&controller=polls');
         $itemid = isset($items[0]) ? '&amp;Itemid=' . $items[0]->id : '';
         $info->title = $row->title;
         $info->userid = $row->created_by;
         $info->link = JRoute::_('index.php?option=com_communitypolls&amp;controller=polls&amp;task=viewpoll&amp;id=' . $row->slug . $itemid);
     }
     return $info;
 }
 function fetchElementOLD($name, $value, &$node, $control_name)
 {
     $options = array();
     $menu =& JApplication::getMenu('site', $options);
     $items = $menu->getMenu();
     $items2 = $menu->getItems("component", "com_joomleague");
     JArrayHelper::sortObjects($items2, "menutype");
     foreach ($items2 as &$item) {
         $item->title = $item->name . " (" . $item->menutype . " - " . $item->component . ")";
         unset($item);
     }
     JArrayHelper::sortObjects($items, "menutype");
     foreach ($items as &$item) {
         if ($item->component != "com_joomleague") {
             $item->title = $item->name . " (" . $item->menutype . " - " . $item->component . ")";
             $items2[] = $item;
             unset($item);
         }
     }
     return JHTML::_('select.genericlist', $items2, '' . $control_name . '[' . $name . ']', '', 'id', 'title', $value, $control_name . $name);
 }
 function getObjectLink($id)
 {
     if (JCOMMENTS_JVERSION == '1.0') {
         $_Itemid = self::getItemid('com_rsgallery2');
         $db = JCommentsFactory::getDBO();
         $db->setQuery('SELECT gallery_id FROM #__rsgallery2_files WHERE id = ' . $id);
         $catid = $db->loadResult();
         $link = sefRelToAbs("index.php?option=com_rsgallery2&amp;page=inline&amp;catid=" . $catid . "&amp;id=" . $id . "&amp;limistart=0&amp;Itemid=" . $_Itemid);
     } else {
         $link = 'index.php?option=com_rsgallery2&page=inline&id=' . $id;
         require_once JPATH_SITE . DS . 'includes' . DS . 'application.php';
         $component = JComponentHelper::getComponent('com_rsgallery2');
         $menus = JApplication::getMenu('site');
         $items = $menus->getItems('componentid', $component->id);
         if (count($items)) {
             $link .= '&Itemid=' . $items[0]->id;
         }
         $link = JRoute::_($link);
     }
     return $link;
 }
Example #17
0
    static function getMenuItemId($needles) {

        $Itemid = JRequest::getInt('Itemid');

        return $Itemid;

        if (!is_array($needles)) {
            if ($needles)
                $needles = array($needles);
            else
                $needles = array();
        }
        $needles['option'] = 'com_bids';

        $menus = JApplication::getMenu('site', array());
        $items = $menus->getItems('query',$needles);

        if (!count($items))
            return $Itemid; //no extension menu items

        $match = reset($items); //fallback first encountered Menuitem

        foreach ($items as $item) {
            if ($match->access != 0 && $item->access == 0) {
                $match = $item; //even better fallback is one that has public access
                continue;
            }

            $xssmatch1 = array_intersect_assoc($item->query, $needles);
            $xssmatch2 = array_intersect_assoc($match->query, $needles);
            if (count($xssmatch1) > count($xssmatch2)) { //better needlematch
                $match = $item; //even better fallback is one that has public access
                continue;
            }
        }

        return $match->id ? $match->id : $Itemid;
    }
Example #18
0
 /**
  * Determines the Itemid
  *
  * searches if a menuitem for this item exists
  * if not the first match will be returned
  *
  * @param array url parameters
  * @since 0.9
  *
  * @return int Itemid
  */
 protected static function _findItem($query)
 {
     $component =& JComponentHelper::getComponent('com_redevent');
     $menus =& JApplication::getMenu('site');
     $items = $menus->getItems('component_id', $component->id);
     $user =& JFactory::getUser();
     $view = isset($query['view']) ? $query['view'] : null;
     if (!$view && isset($query['controller']) && $query['controller'] == 'registration') {
         $view = 'details';
     }
     if ($items) {
         foreach ($items as $item) {
             if ($view && @$item->query['view'] == $view) {
                 switch ($view) {
                     case 'details':
                         if (isset($query['xref']) && (int) $query['xref'] == (int) @$item->query['xref']) {
                             return $item;
                         }
                         // needs a second round to check just for 'id'
                         break;
                     default:
                         if (!isset($query['id']) || (int) @$item->query['id'] == (int) @$query['id']) {
                             return $item;
                         }
                 }
             }
         }
         // second round for view with optional params
         foreach ($items as $item) {
             if (isset($view) && @$item->query['view'] == $view) {
                 switch ($view) {
                     case 'details':
                         if (isset($query['id']) && (int) $query['id'] == (int) @$item->query['id']) {
                             return $item;
                         }
                         // needs a second round to check just for 'id'
                         break;
                 }
             }
         }
     }
     return false;
 }
Example #19
0
 function getCalendarLink($myItemid, $catout, $event = FALSE, $evid = NULL)
 {
     $menu =& JApplication::getMenu('site');
     $menuItem = $menu->getItem($myItemid);
     if ($event) {
         $task = "icalrepeat.detail&evid=" . $evid;
     } else {
         if ($menuItem && $menuItem->component == JEV_COM_COMPONENT) {
             $task = $menuItem->query["task"];
         } else {
             $task = "month.calendar";
         }
     }
     return JRoute::_("index.php?option=" . JEV_COM_COMPONENT . "&Itemid=" . $myItemid . "&task=" . $task . $catout, true);
 }
Example #20
0
 function _findItem($needles)
 {
     $component =& JComponentHelper::getComponent('com_k2');
     $menus =& JApplication::getMenu('site', array());
     if (K2_JVERSION == '16') {
         $items = $menus->getItems('component_id', $component->id);
     } else {
         $items = $menus->getItems('componentid', $component->id);
     }
     $match = null;
     foreach ($needles as $needle => $id) {
         if (count($items)) {
             foreach ($items as $item) {
                 if ($needle == 'user' || $needle == 'category') {
                     if (@$item->query['task'] == $needle && @$item->query['id'] == $id) {
                         $match = $item;
                         break;
                     }
                 } else {
                     if ($needle == 'tag') {
                         if (@$item->query['task'] == $needle && @$item->query['tag'] == $id) {
                             $match = $item;
                             break;
                         }
                     } else {
                         if (@$item->query['view'] == $needle && @$item->query['id'] == $id) {
                             $match = $item;
                             break;
                         }
                     }
                 }
                 if (!is_null($match)) {
                     break;
                 }
             }
             // Second pass [START]
             // Only for multiple categories links. Triggered only if we do not have find any match (link to direct category)
             if (is_null($match)) {
                 foreach ($items as $item) {
                     if ($needle == 'category') {
                         if (!isset($item->K2Categories)) {
                             if (K2_JVERSION == '15') {
                                 $menuparams = explode("\n", $item->params);
                                 foreach ($menuparams as $param) {
                                     if (strpos($param, 'categories=') === 0) {
                                         $array = explode('categories=', $param);
                                         $item->K2Categories = explode('|', $array[1]);
                                     }
                                 }
                             } else {
                                 $menuparams = json_decode($item->params);
                                 $item->K2Categories = isset($menuparams->categories) ? $menuparams->categories : array();
                             }
                         }
                         if (isset($item->K2Categories) && is_array($item->K2Categories)) {
                             foreach ($item->K2Categories as $catid) {
                                 if (@$item->query['view'] == 'itemlist' && @$item->query['task'] == '' && @(int) $catid == $id) {
                                     $match = $item;
                                     break;
                                 }
                             }
                         }
                     }
                     if (!is_null($match)) {
                         break;
                     }
                 }
             }
             // Second pass [END]
         }
         if (!is_null($match)) {
             break;
         }
     }
     return $match;
 }
Example #21
0
	/**
	 * Return a reference to the JPathway object.
	 *
	 * @access public
	 * @return object JPathway.
	 * @since 1.5
	 */
	function &getMenu()
	{
		$options = array();
		$menu =& parent::getMenu('site', $options);
		return $menu;
	}
Example #22
0
 function getHomeQueries($includeLang = true)
 {
     $menu =& JApplication::getMenu('site');
     $item =& $menu->getDefault();
     $link = $item->link;
     $uri = new JURI($link);
     // We need to adjust the URL according to the extension
     SEFTools::normalizeURI($uri);
     if ($includeLang) {
         $uri->setVar('lang', '');
     }
     $q = JoomSEF::_uriToUrl($uri);
     return array($q, $item->id);
 }
Example #23
0
global $sh_LANG;
$sefConfig =& shRouter::shGetConfig();
$shLangName = '';
$shLangIso = '';
$title = array();
$shItemidString = '';
$sefSuffix = $sefConfig->suffix;
$dosef = shInitializePlugin($lang, $shLangName, $shLangIso, $option);
if ($dosef == false) {
    return;
}
// ------------------  standard plugin initialize function - don't change ---------------------------
$view = isset($view) ? $view : null;
if (empty($Itemid)) {
    $component =& JComponentHelper::getComponent('com_xmap');
    $menus =& JApplication::getMenu('site', array());
    $items = $menus->getItems('componentid', $component->id);
    if (count($items)) {
        $match = null;
        foreach ($items as $item) {
            if (@$item->query['view'] == $view && @$item->query['sitemap'] == $sitemap) {
                $match = $item;
                break;
            }
        }
        if (!$match) {
            $match = $items[0];
        }
        $Itemid = $match->id;
    }
}
Example #24
0
 private function targetMenu($itemid = 0, $name)
 {
     $db =& JFactory::getDBO();
     // assemble menu items to the array
     $options = array();
     $options[] = JHTML::_('select.option', '', '- ' . JText::_('SELECT_ITEM') . ' -');
     // load the list of menu types
     // TODO: move query to model
     $query = 'SELECT menutype, title' . ' FROM #__menu_types' . ' ORDER BY title';
     $db->setQuery($query);
     $menuTypes = $db->loadObjectList();
     $menu =& JApplication::getMenu('site');
     $menuItems = $menu->getMenu();
     foreach ($menuItems as &$item) {
         if ($item->component == "com_jevents") {
             if (version_compare(JVERSION, '1.6.0', ">=")) {
                 $item->title = "*** " . $item->title . " ***";
             } else {
                 $item->name = "*** " . $item->name . " ***";
             }
         }
         unset($item);
     }
     // establish the hierarchy of the menu
     $children = array();
     if ($menuItems) {
         // first pass - collect children
         foreach ($menuItems as $v) {
             $pt = 0;
             //(version_compare(JVERSION, '1.6.0', ">=")) ? $v->parent_id: $v->parent;  // RSH 10/4/10 in J!1.5 - parent was always 0, this changed in J!.16 to a real parent_id, so force id to 0 for compatibility
             $list = @$children[0] ? $children[0] : array();
             array_push($list, $v);
             $children[0] = $list;
         }
     }
     // second pass - get an indent list of the items
     $list = JHTML::_('menu.treerecurse', 0, '', array(), $children, 9999, 0, 0);
     // assemble into menutype groups
     $n = count($list);
     $groupedList = array();
     foreach ($list as $k => $v) {
         $groupedList[$v->menutype][] =& $list[$k];
     }
     foreach ($menuTypes as $type) {
         $options[] = JHTML::_('select.option', $type->menutype, $type->title, 'value', 'text', true);
         // these are disabled! (true)
         if (isset($groupedList[$type->menutype])) {
             $n = count($groupedList[$type->menutype]);
             for ($i = 0; $i < $n; $i++) {
                 $item =& $groupedList[$type->menutype][$i];
                 $disable = false;
                 $text = version_compare(JVERSION, '1.6.0', ">=") ? '     ' . html_entity_decode($item->treename) : '&nbsp;&nbsp;&nbsp;' . $item->treename;
                 $text = str_repeat("&nbsp;", (isset($item->level) ? $item->level : $item->sublevel) * 4) . $text;
                 $options[] = JHTML::_('select.option', $item->id, $text, 'value', 'text', $disable);
             }
         }
     }
     return JHTML::_('select.genericlist', $options, '' . $name, 'class="inputbox"', 'value', 'text', $itemid, $name);
 }
Example #25
0
 function processArticle($article, $art, $text = '', $type = 'article')
 {
     if ($type == 'k2' && !$this->params->dbselects_k2) {
         $type = '';
     }
     $regex = '#\\{(/?[^\\}]+)\\}#si';
     if (preg_match_all($regex, $text, $matches, PREG_SET_ORDER) > 0) {
         if ($type == 'k2') {
             $selects = $this->params->dbselects_k2;
         } else {
             $selects = $this->params->dbselects_content;
         }
         foreach ($matches as $match) {
             $data = trim($match['1']);
             if (!(strpos($data, 'intro') === false)) {
                 $selects[] = 'introtext';
             } else {
                 if (!(strpos($data, 'full') === false)) {
                     $selects[] = 'fulltext';
                 } else {
                     if (!(strpos($data, 'text') === false)) {
                         $selects[] = 'introtext';
                         $selects[] = 'fulltext';
                     }
                 }
             }
         }
         $selects = array_unique($selects);
         $selects = 'c.`' . implode('`, c.`', $selects) . '`';
         $joins = '';
         if ($type == 'article') {
             $selects .= ', CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(":", c.id, c.alias) ELSE c.id END as slug';
             $selects .= ', CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END as catslug';
             $joins = ' LEFT JOIN #__categories as cc ON cc.id = c.catid';
         }
         $where = ' AND ( c.title = ' . $this->database->quote(NoNumberElementsFunctions::html_entity_decoder($article));
         $where .= ' OR c.alias = ' . $this->database->quote(NoNumberElementsFunctions::html_entity_decoder($article));
         if (is_numeric($article)) {
             $where .= ' OR c.id = ' . $article;
         }
         $where .= ' ) ';
         if (!$this->params->ignore_state) {
             $jnow =& JFactory::getDate();
             $now = $jnow->toMySQL();
             $nullDate = $this->database->getNullDate();
             if ($type == 'k2') {
                 $where .= ' AND c.published = 1 AND trash = 0';
             } else {
                 $where .= ' AND c.state = 1';
             }
             $where .= ' AND ( c.publish_up = ' . $this->database->quote($nullDate) . ' OR c.publish_up <= ' . $this->database->quote($now) . ' )' . ' AND ( c.publish_down = ' . $this->database->quote($nullDate) . ' OR c.publish_down >= ' . $this->database->quote($now) . ' )';
         }
         $query = 'SELECT ' . $selects . ' FROM ' . ($type == 'k2' ? '#__k2_items as c' : '#__content as c') . $joins . ' WHERE c.access ' . (defined('_JACL') ? 'IN (' . $this->params->aid_jaclplus . ')' : '<= ' . (int) $this->params->aid) . $where . ' ORDER BY c.ordering' . ' LIMIT 1';
         $this->database->setQuery($query);
         $article = $this->database->loadObject();
         if (!$article) {
             return '<!-- ' . JText::_('AA_ACCESS_TO_ARTICLE_DENIED') . ' -->';
         }
         $ifregex = '#\\{if:([^\\}]+)\\}(.*?)(?:\\{else\\}(.*?))?\\{/if\\}#si';
         if (preg_match_all($ifregex, $text, $ifs, PREG_SET_ORDER) > 0) {
             foreach ($ifs as $if) {
                 $pass = 0;
                 $eval = '$pass = ( ( $article->' . str_replace('=', '==', trim($if['1'])) . ' ) ? 1 : 0 );';
                 $eval = str_replace('$article->!', '!$article->', $eval);
                 eval($eval);
                 if (!$pass) {
                     $text = str_replace($if['0'], isset($if['3']) ? $if['3'] : '', $text);
                 } else {
                     $text = str_replace($if['0'], $if['2'], $text);
                 }
             }
         }
     }
     if (preg_match_all($regex, $text, $matches, PREG_SET_ORDER) > 0) {
         foreach ($matches as $match) {
             $data = trim($match['1']);
             $ok = 0;
             $str = '';
             $data = explode(':', $data, 2);
             $tag = trim($data['0']);
             $extra = isset($data['1']) ? trim($data['1']) : '';
             if ($tag == '/link') {
                 $str = '</a>';
                 $ok = 1;
             } else {
                 if ($tag == '/div') {
                     $str = '</div>';
                     $ok = 1;
                 } else {
                     if ($tag == 'div' || strpos($tag, 'div ') === 0) {
                         if ($tag != 'div') {
                             $extra = str_replace('div ', '', $tag) . ':' . $extra;
                         }
                         $str = '';
                         if ($extra) {
                             $extra = explode('|', $extra);
                             $extras = new stdClass();
                             foreach ($extra as $e) {
                                 if (!(strpos($e, ':') === false)) {
                                     list($key, $val) = explode(':', $e, 2);
                                     $extras->{$key} = $val;
                                 }
                             }
                             if (isset($extras->class)) {
                                 $str .= 'class="' . $extras->class . '"';
                             }
                             $style = array();
                             if (isset($extras->width)) {
                                 if (is_numeric($extras->width)) {
                                     $extras->width .= 'px';
                                 }
                                 $style[] = 'width:' . $extras->width;
                             }
                             if (isset($extras->height)) {
                                 if (is_numeric($extras->height)) {
                                     $extras->height .= 'px';
                                 }
                                 $style[] = 'height:' . $extras->height;
                             }
                             if (isset($extras->align)) {
                                 $style[] = 'float:' . $extras->align;
                             } else {
                                 if (isset($extras->float)) {
                                     $style[] = 'float:' . $extras->float;
                                 }
                             }
                             if (!empty($style)) {
                                 $str .= ' style="' . implode(';', $style) . ';"';
                             }
                         }
                         $str = trim('<div ' . trim($str)) . '>';
                         $ok = 1;
                     } else {
                         if ($tag == 'link' || $tag == 'url' || !(strpos($tag, 'readmore') === false)) {
                             if (isset($article->id)) {
                                 if ($type == 'k2') {
                                     $link = 'index.php?option=com_k2&view=item&id=' . $article->id;
                                     $component =& JComponentHelper::getComponent('com_k2');
                                     $menus =& JApplication::getMenu('site', array());
                                     $menuitems = $menus->getItems('componentid', $component->id);
                                     $id = 0;
                                     if (is_array($menuitems)) {
                                         foreach ($menuitems as $item) {
                                             if (@$item->query['view'] == 'item' && @$item->query['layout'] == 'item' && @$item->query['id'] == $article->id) {
                                                 $id = $item->id;
                                                 break;
                                             }
                                         }
                                         if (!$id) {
                                             foreach ($menuitems as $item) {
                                                 if (@$item->query['view'] == 'itemlist' && @$item->query['layout'] == 'category' && @$item->query['id'] == $article->catid) {
                                                     $id = $item->id;
                                                     break;
                                                 }
                                             }
                                         }
                                     }
                                 } else {
                                     $slug = 'id=' . $article->slug;
                                     if ($article->catid) {
                                         $slug .= '&catid=' . $article->catslug;
                                     }
                                     $link = 'index.php?option=com_content&view=article&' . $slug;
                                     $component =& JComponentHelper::getComponent('com_content');
                                     $menus =& JApplication::getMenu('site', array());
                                     $menuitems = $menus->getItems('componentid', $component->id);
                                     $id = 0;
                                     if (is_array($menuitems)) {
                                         foreach ($menuitems as $item) {
                                             if (@$item->query['view'] == 'article' && @$item->query['id'] == $article->id) {
                                                 $id = $item->id;
                                                 break;
                                             }
                                         }
                                         if (!$id) {
                                             foreach ($menuitems as $item) {
                                                 if (@$item->query['view'] == 'category' && @$item->query['id'] == $article->catid) {
                                                     $id = $item->id;
                                                     break;
                                                 }
                                             }
                                         }
                                         if (!$id) {
                                             foreach ($menuitems as $item) {
                                                 if (@$item->query['view'] == 'section' && @$item->query['id'] == $article->sectionid) {
                                                     $id = $item->id;
                                                     break;
                                                 }
                                             }
                                         }
                                     }
                                 }
                                 if ($id) {
                                     $link .= '&Itemid=' . $id;
                                 }
                                 $link = JRoute::_($link);
                                 if ($tag == 'link') {
                                     $str = '<a href="' . $link . '">';
                                 } else {
                                     if ($tag == 'url') {
                                         $str = $link;
                                     } else {
                                         $readmore = JText::_('Read more...');
                                         $class = 'readon';
                                         if ($extra) {
                                             $extra = explode('|', $extra);
                                             if (trim($extra['0'])) {
                                                 $readmore = JText::_(trim($extra['0']));
                                             }
                                             if (isset($extra['1'])) {
                                                 $class = trim($extra['1']);
                                             }
                                         }
                                         $str = '<a href="' . $link . '" class="' . $class . '">' . $readmore . '</a>';
                                     }
                                 }
                                 $ok = 1;
                             }
                         } else {
                             if (!(strpos($tag, 'text') === false) || !(strpos($tag, 'intro') === false) || !(strpos($tag, 'full') === false)) {
                                 // TEXT data
                                 $article->text = '';
                                 if (!(strpos($tag, 'intro') === false)) {
                                     if (isset($article->introtext)) {
                                         $article->text = $article->introtext;
                                         $ok = 1;
                                     }
                                 } else {
                                     if (!(strpos($tag, 'full') === false)) {
                                         if (isset($article->fulltext)) {
                                             $article->text = $article->fulltext;
                                             $ok = 1;
                                         }
                                     } else {
                                         if (!(strpos($tag, 'text') === false)) {
                                             if (isset($article->introtext) && isset($article->fulltext)) {
                                                 $article->text = $article->introtext . $article->fulltext;
                                                 $ok = 1;
                                             }
                                         }
                                     }
                                 }
                                 if ($type == 'k2') {
                                     $article->parameters = new JParameter($article->params);
                                 } else {
                                     $article->parameters = new JParameter($article->attribs);
                                 }
                                 if ($this->params->run_content_plugins) {
                                     if (!$this->params->dispatcher) {
                                         $plugins = JPluginHelper::_load();
                                         foreach ($plugins as $plugin) {
                                             if ($plugin->type == 'content' || $plugin->type == 'system' || $plugin->type == 'k2') {
                                                 JPluginHelper::_import($plugin);
                                             }
                                         }
                                         $this->params->dispatcher = clone JDispatcher::getInstance();
                                         foreach ($this->params->dispatcher->_observers as $i => $observer) {
                                             if (!is_array($observer) && ($observer->_name == 'articlesanywhere' || $observer->_name == 'betterpreview')) {
                                                 unset($this->params->dispatcher->_observers[$i]);
                                             }
                                         }
                                     }
                                     $this->params->dispatcher->trigger('onPrepareContent', array(&$article, &$article->parameters, 0));
                                 }
                                 $str = $article->text;
                                 if ($extra) {
                                     $attribs = explode(':', $extra);
                                     $max = 0;
                                     $strip = 0;
                                     foreach ($attribs as $attrib) {
                                         if (trim($attrib) == 'strip') {
                                             $strip = 1;
                                         } else {
                                             $max = $attrib;
                                         }
                                     }
                                     $word_limit = !(strpos($max, 'word') === false);
                                     if ($strip) {
                                         // remove pagenavcounter
                                         $str = preg_replace('#(<' . 'div class="pagenavcounter">.*?</div>)#si', ' ', $str);
                                         // remove pagenavbar
                                         $str = preg_replace('#(<' . 'div class="pagenavbar">(<div>.*?</div>)*</div>)#si', ' ', $str);
                                         // remove scripts
                                         $str = preg_replace('#(<' . 'script[^a-z0-9].*?</script>)#si', ' ', $str);
                                         $str = preg_replace('#(<' . 'noscript[^a-z0-9].*?</noscript>)#si', ' ', $str);
                                         // remove other tags
                                         $str = preg_replace('#(<' . '/?[a-z][a-z0-9]?.*?>)#si', ' ', $str);
                                         // remove double whitespace
                                         $str = trim(preg_replace('#\\s+#s', ' ', $str));
                                         if ($max) {
                                             $orig_len = strlen($str);
                                             if ($word_limit) {
                                                 // word limit
                                                 $str = trim(preg_replace('#^(([^\\s]+\\s*){' . (int) $max . '}).*$#s', '\\1', $str));
                                                 if (strlen($str) < $orig_len) {
                                                     if (preg_match('#[^a-z0-9]$#si', $str)) {
                                                         $str .= ' ';
                                                     }
                                                     if ($this->params->use_ellipsis) {
                                                         $str .= '...';
                                                     }
                                                 }
                                             } else {
                                                 // character limit
                                                 $max = (int) $max;
                                                 if ($max < $orig_len) {
                                                     $str = rtrim(substr($str, 0, $max - 3));
                                                     if (preg_match('#[^a-z0-9]$#si', $str)) {
                                                         $str .= ' ';
                                                     }
                                                     if ($this->params->use_ellipsis) {
                                                         $str .= '...';
                                                     }
                                                 }
                                             }
                                         }
                                     } else {
                                         if ($max && ($word_limit || (int) $max < strlen($str))) {
                                             $max = (int) $max;
                                             // store pagenavcounter & pagenav (exclude from count)
                                             preg_match('#<' . 'div class="pagenavcounter">.*?</div>#si', $str, $pagenavcounter);
                                             $pagenavcounter = isset($pagenavcounter['0']) ? $pagenavcounter['0'] : '';
                                             if ($pagenavcounter) {
                                                 $str = str_replace($pagenavcounter, '<!-- ARTA_PAGENAVCOUNTER -->', $str);
                                             }
                                             preg_match('#<' . 'div class="pagenavbar">(<div>.*?</div>)*</div>#si', $str, $pagenav);
                                             $pagenav = isset($pagenav['0']) ? $pagenav['0'] : '';
                                             if ($pagenav) {
                                                 $str = str_replace($pagenav, '<!-- ARTA_PAGENAV -->', $str);
                                             }
                                             // add explode helper strings around tags
                                             $explode_str = '<!-- ARTA_TAG -->';
                                             $str = preg_replace('#(<\\/?[a-z][a-z0-9]?.*?>|<!--.*?-->)#si', $explode_str . '\\1' . $explode_str, $str);
                                             $str_array = explode($explode_str, $str);
                                             $str = array();
                                             $tags = array();
                                             $count = 0;
                                             $is_script = 0;
                                             foreach ($str_array as $i => $str_part) {
                                                 if (fmod($i, 2)) {
                                                     // is tag
                                                     $str[] = $str_part;
                                                     preg_match('#^<(\\/?([a-z][a-z0-9]*))#si', $str_part, $tag);
                                                     if (!empty($tag)) {
                                                         if ($tag['1'] == 'script') {
                                                             $is_script = 1;
                                                         }
                                                         if (!$is_script && strpos($str_part, '/>') === false && !in_array($tag['2'], array('area', 'br', 'hr', 'img', 'input', 'param'))) {
                                                             $tags[] = $tag['1'];
                                                         }
                                                         if ($tag['1'] == '/script') {
                                                             $is_script = 0;
                                                         }
                                                     }
                                                 } else {
                                                     if ($is_script) {
                                                         $str[] = $str_part;
                                                     } else {
                                                         if ($word_limit) {
                                                             // word limit
                                                             if ($str_part) {
                                                                 $words = explode(' ', trim($str_part));
                                                                 $word_count = count($words);
                                                                 if ($max < $count + $word_count) {
                                                                     $words_part = array();
                                                                     $word_count = 0;
                                                                     foreach ($words as $word) {
                                                                         if ($word) {
                                                                             $word_count++;
                                                                         }
                                                                         if ($max < $count + $word_count) {
                                                                             break;
                                                                         }
                                                                         $words_part[] = $word;
                                                                     }
                                                                     $string = rtrim(implode(' ', $words_part));
                                                                     if (preg_match('#[^a-z0-9]$#si', $string)) {
                                                                         $string .= ' ';
                                                                     }
                                                                     if ($this->params->use_ellipsis) {
                                                                         $string .= '...';
                                                                     }
                                                                     $str[] = $string;
                                                                     break;
                                                                 }
                                                                 $count += $word_count;
                                                             }
                                                             $str[] = $str_part;
                                                         } else {
                                                             // character limit
                                                             if ($max < $count + strlen($str_part)) {
                                                                 // strpart has to be cut off
                                                                 $maxlen = $max - $count;
                                                                 if ($maxlen < 3) {
                                                                     $string = '';
                                                                     if (preg_match('#[^a-z0-9]$#si', $str_part)) {
                                                                         $string .= ' ';
                                                                     }
                                                                     if ($this->params->use_ellipsis) {
                                                                         $string .= '...';
                                                                     }
                                                                     $str[] = $string;
                                                                 } else {
                                                                     $string = rtrim(substr($str_part, 0, $maxlen - 3));
                                                                     if (preg_match('#[^a-z0-9]$#si', $string)) {
                                                                         $string .= ' ';
                                                                     }
                                                                     if ($this->params->use_ellipsis) {
                                                                         $string .= '...';
                                                                     }
                                                                     $str[] = $string;
                                                                 }
                                                                 break;
                                                             }
                                                             $count += strlen($str_part);
                                                             $str[] = $str_part;
                                                         }
                                                     }
                                                 }
                                             }
                                             // revers sort open tags
                                             krsort($tags);
                                             $tags = array_values($tags);
                                             $count = count($tags);
                                             for ($i = 0; $i < 3; $i++) {
                                                 foreach ($tags as $ti => $tag) {
                                                     if ($tag['0'] == '/') {
                                                         for ($oi = $ti + 1; $oi < $count; $oi++) {
                                                             $opentag = $tags[$oi];
                                                             if ($opentag == $tag) {
                                                                 break;
                                                             }
                                                             if ('/' . $opentag == $tag) {
                                                                 unset($tags[$ti]);
                                                                 unset($tags[$oi]);
                                                                 break;
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                             foreach ($tags as $tag) {
                                                 // add closing tag to end of string
                                                 if ($tag['0'] != '/') {
                                                     $str[] = '</' . $tag . '>';
                                                 }
                                             }
                                             $str = implode('', $str);
                                             $str = str_replace(array('<!-- ARTA_PAGENAVCOUNTER -->', '<!-- ARTA_PAGENAV -->'), array($pagenavcounter, $pagenav), $str);
                                         }
                                     }
                                 }
                                 if ($art && isset($art->id) && $art->id) {
                                     $str = str_replace('view=article&amp;id=' . $art->id, 'view=article&amp;id=' . $article->id, $str);
                                 }
                             } else {
                                 // Get data from db columns
                                 if (isset($article->{$tag})) {
                                     $str = $article->{$tag};
                                     $ok = 1;
                                 }
                                 // otherwise get data from parameter data
                                 if (!$ok) {
                                     $params = new stdClass();
                                     if (isset($article->attribs)) {
                                         $params = $this->parameters->getParams($article->attribs);
                                     } else {
                                         if (isset($article->params)) {
                                             $params = $this->parameters->getParams($article->params);
                                         }
                                     }
                                     if ($params && isset($params->{$tag})) {
                                         $str = $params->{$tag};
                                         $ok = 1;
                                     }
                                 }
                                 // otherwise get data from extra fields (for k2 items)
                                 if (!$ok && $type == 'k2') {
                                     $extravalue = $this->getExtraFieldValue($article->extra_fields, $tag, $article->catid);
                                     if ($extravalue !== null) {
                                         $str = $extravalue;
                                         $ok = 1;
                                     }
                                 }
                                 if ($ok && !(strpos($str, '-') == false) && !preg_match('#[a-z]#i', $str) && strtotime($str)) {
                                     if ($extra && strpos($extra, '%') === false) {
                                         $extra = NoNumberElementsFunctions::dateToStrftimeFormat($extra);
                                     }
                                     $str = JHTML::_('date', strtotime($str), $extra);
                                 }
                             }
                         }
                     }
                 }
             }
             if ($ok) {
                 $text = str_replace($match['0'], $str, $text);
             }
         }
     }
     return $text;
 }
Example #26
0
 /**
  * Returns the application JPathway object.
  *
  * @param   string  $name     The name of the application/client.
  * @param   array   $options  An optional associative array of configuration settings.
  * @return  void
  */
 public function getMenu($name = null, $options = array())
 {
     //die('getMenu() invalid in API application context');
     $options = array();
     $menu = parent::getMenu('site', $options);
     return $menu;
 }
Example #27
0
 /**
  * Return a reference to the JPathway object.
  *
  * @param   string    $name        The name of the application/client.
  * @param   array     $options     An optional associative array of configuration settings.
  *
  * @return  object  JMenu.
  * @since   1.5
  */
 public function getMenu($name = null, $options = array())
 {
     $options = array();
     $menu = parent::getMenu('site', $options);
     return $menu;
 }
Example #28
0
 protected static function _findItem($needles)
 {
     // Prepare the reverse lookup array.
     if (self::$lookup === null) {
         self::$lookup = array();
         $component = JComponentHelper::getComponent('com_temakorok');
         $menus = JApplication::getMenu('site');
         $field = 'component_id';
         $items = $menus->getItems($field, $component->id);
         foreach ($items as $item) {
             if (isset($item->query) && isset($item->query['view'])) {
                 $view = $item->query['view'];
                 if (!isset(self::$lookup[$view])) {
                     self::$lookup[$view] = array();
                 }
                 if (isset($item->query['id'])) {
                     self::$lookup[$view][$item->query['id']] = $item->id;
                 }
             }
         }
     }
     foreach ($needles as $view => $ids) {
         if (isset(self::$lookup[$view])) {
             foreach ($ids as $id) {
                 if (isset(self::$lookup[$view][(int) $id])) {
                     return self::$lookup[$view][(int) $id];
                 }
             }
         }
     }
     return null;
 }
Example #29
0
 function install($theme)
 {
     global $mainframe;
     $package = $this->_getPackageFromUpload();
     if (!$package) {
         JError::raiseWarning(1, JText::_('Unable to find install package'));
         $this->deleteTempFiles();
         return false;
     }
     if ($package['dir'] && JFolder::exists($package['dir'])) {
         $this->setPath('source', $package['dir']);
     } else {
         JError::raiseWarning(1, JText::_('Install path does not exist'));
         $this->deleteTempFiles();
         return false;
     }
     // We need to find the installation manifest file
     if (!$this->_findManifest()) {
         JError::raiseWarning(1, JText::_('Unable to find required information in install package'));
         $this->deleteTempFiles();
         return false;
     }
     // Files - copy files in manifest
     foreach ($this->_manifest->document->children() as $child) {
         if (is_a($child, 'JSimpleXMLElement') && $child->name() == 'files') {
             if ($this->parseFiles($child) === false) {
                 JError::raiseWarning(1, JText::_('Unable to find required information in install package'));
                 $this->deleteTempFiles();
                 return false;
             }
         }
     }
     // File - copy the xml file
     $copyFile = array();
     $path['src'] = $this->getPath('manifest');
     // XML file will be copied too
     $path['dest'] = JPATH_SITE . DS . 'components' . DS . 'com_phocagallery' . DS . 'assets' . DS . 'images' . DS . basename($this->getPath('manifest'));
     $copyFile[] = $path;
     $this->copyFiles($copyFile);
     $this->deleteTempFiles();
     // -------------------
     // Themes
     // -------------------
     // Params -  Get new themes params
     $paramsThemes =& $this->getParamsThemes();
     // -------------------
     // Component
     // -------------------
     if (isset($theme['component']) && $theme['component'] == 1) {
         $paramsComponentArray = '';
         // Params - Get component params
         //	$paramsComponent = $this->getParams();
         $paramsComponent = JComponentHelper::getParams('com_phocagallery');
         $paramsComponentArray = $paramsComponent->_registry['_default']['data'];
         // if empty object, php doesn't say it...
         $isArray = 0;
         foreach ($paramsComponentArray as $isKey => $isValue) {
             $isArray = 1;
         }
         // If no params are saved, we add only Themes params
         if ($isArray == 1) {
             // We get the params values from database and add new values ( no lose the other params)
             $newParamsComponent = '';
             foreach ($paramsComponentArray as $keyC => $valueC) {
                 $newParamsComponent['params'][$keyC] = $valueC;
                 foreach ($paramsThemes as $keyT => $valueT) {
                     if ($valueT['name'] == $keyC) {
                         $newParamsComponent['params'][$keyC] = $valueT['value'];
                     }
                 }
             }
         } else {
             $newParamsComponent = '';
             foreach ($paramsThemes as $keyT => $valueT) {
                 $newParamsComponent['params'][$valueT['name']] = $valueT['value'];
             }
         }
         $table =& JTable::getInstance('component');
         $table->loadByOption('com_phocagallery');
         if (!$table->bind($newParamsComponent)) {
             JError::raiseWarning(500, 'Not a valid component');
             return false;
         }
         // pre-save checks
         if (!$table->check()) {
             JError::raiseWarning(500, $table->getError('Check Problem'));
             return false;
         }
         // save the changes
         if (!$table->store()) {
             JError::raiseWarning(500, $table->getError('Store Problem'));
             return false;
         }
     }
     // -------------------
     // Menu Categories
     // -------------------
     if (isset($theme['categories']) && $theme['categories'] == 1) {
         $menus =& JApplication::getMenu('site');
         $db =& JFactory::getDBO();
         $itemsCat = $menus->getItems('link', 'index.php?option=com_phocagallery&view=categories');
         if (!empty($itemsCat)) {
             foreach ($itemsCat as $keyIT => $valueIT) {
                 $paramsCategoriesArray = '';
                 $query = 'SELECT m.params' . ' FROM #__menu AS m' . ' WHERE m.id = ' . (int) $valueIT->id;
                 $db->setQuery($query);
                 $paramsCategoriesObject = $db->loadObjectList();
                 $paramsCategories = new JParameter($paramsCategoriesObject[0]->params);
                 $paramsCategoriesArray = $paramsCategories->_registry['_default']['data'];
                 // if empty object, php doesn't say it...
                 $isArray = 0;
                 foreach ($paramsCategoriesArray as $isKey => $isValue) {
                     $isArray = 1;
                 }
                 // If no params are saved, we add only Themes params
                 if ($isArray == 1) {
                     // We get the params values from database and add new values ( no lose the other params)
                     $newParamsMenuCategories = '';
                     foreach ($paramsCategoriesArray as $keyS => $valueS) {
                         $newParamsMenuCategories['params'][$keyS] = $valueS;
                         foreach ($paramsThemes as $keyT2 => $valueT2) {
                             if ($valueT2['name'] == $keyS) {
                                 $newParamsMenuCategories['params'][$keyS] = $valueT2['value'];
                             }
                         }
                     }
                 } else {
                     $newParamsMenuCategories = '';
                     foreach ($paramsThemes as $keyT2 => $valueT2) {
                         $newParamsMenuCategories['params'][$valueT2['name']] = $valueT2['value'];
                     }
                 }
                 $table =& JTable::getInstance('menu');
                 if (!$table->load((int) $valueIT->id)) {
                     JError::raiseWarning(500, 'Not a valid table');
                     return false;
                 }
                 if (!$table->bind($newParamsMenuCategories)) {
                     JError::raiseWarning(500, 'Not a valid table');
                     return false;
                 }
                 // pre-save checks
                 if (!$table->check()) {
                     JError::raiseWarning(500, $table->getError('Check Problem'));
                     return false;
                 }
                 // save the changes
                 if (!$table->store()) {
                     JError::raiseWarning(500, $table->getError('Store Problem'));
                     return false;
                 }
             }
         }
     }
     // -------------------
     // Menu Category
     // -------------------
     if (isset($theme['category']) && $theme['category'] == 1) {
         $menus =& JApplication::getMenu('site');
         $db =& JFactory::getDBO();
         // Select all categories to get possible menu links
         $query = 'SELECT c.id' . ' FROM #__phocagallery_categories AS c';
         $db->setQuery($query);
         $categoriesId = $db->loadObjectList();
         // We get id from Phoca Gallery categories and try to find menu links from these categories
         if (!empty($categoriesId)) {
             foreach ($categoriesId as $keyI => $valueI) {
                 $itemsCat = $menus->getItems('link', 'index.php?option=com_phocagallery&view=category&id=' . (int) $valueI->id);
                 if (!empty($itemsCat)) {
                     foreach ($itemsCat as $keyIT2 => $valueIT2) {
                         $paramsCategoryArray = '';
                         $query = 'SELECT m.params' . ' FROM #__menu AS m' . ' WHERE m.id = ' . (int) $valueIT2->id;
                         $db->setQuery($query);
                         $paramsCategoryObject = $db->loadObjectList();
                         $paramsCategory = new JParameter($paramsCategoryObject[0]->params);
                         $paramsCategoryArray = $paramsCategory->_registry['_default']['data'];
                         // if empty object, php doesn't say it...
                         $isArray = 0;
                         foreach ($paramsCategoryArray as $isKey => $isValue) {
                             $isArray = 1;
                         }
                         // If no params are saved, we add only Themes params
                         if ($isArray == 1) {
                             // We get the params values from database and add new values ( no lose the other params)
                             $newParamsMenuCategory = '';
                             foreach ($paramsCategoryArray as $keyY => $valueY) {
                                 $newParamsMenuCategory['params'][$keyY] = $valueY;
                                 foreach ($paramsThemes as $keyT3 => $valueT3) {
                                     if ($valueT3['name'] == $keyY) {
                                         $newParamsMenuCategory['params'][$keyY] = $valueT3['value'];
                                     }
                                 }
                             }
                         } else {
                             $newParamsMenuCategory = '';
                             foreach ($paramsThemes as $keyT3 => $valueT3) {
                                 $newParamsMenuCategory['params'][$valueT3['name']] = $valueT3['value'];
                             }
                         }
                         $table =& JTable::getInstance('menu');
                         if (!$table->load((int) $valueIT2->id)) {
                             JError::raiseWarning(500, 'Not a valid table');
                             return false;
                         }
                         if (!$table->bind($newParamsMenuCategory)) {
                             JError::raiseWarning(500, 'Not a valid table');
                             return false;
                         }
                         // pre-save checks
                         if (!$table->check()) {
                             JError::raiseWarning(500, $table->getError('Check Problem'));
                             return false;
                         }
                         // save the changes
                         if (!$table->store()) {
                             JError::raiseWarning(500, $table->getError('Store Problem'));
                             return false;
                         }
                     }
                 }
             }
         }
     }
     return true;
 }
Example #30
0
 function _findItem($needles, $notCheckId = 0)
 {
     //$component =& JComponentHelper::getComponent('com_phocagallery');
     $menus =& JApplication::getMenu('site', array());
     $items = $menus->getItems('component', 'com_phocagallery');
     if (!$items) {
         return JRequest::getVar('Itemid', 0, '', 'int');
         //return null;
     }
     $match = null;
     foreach ($needles as $needle => $id) {
         if ($notCheckId == 0) {
             foreach ($items as $item) {
                 if (@$item->query['view'] == $needle && @$item->query['id'] == $id) {
                     $match = $item;
                     break;
                 }
             }
         } else {
             foreach ($items as $item) {
                 if (@$item->query['view'] == $needle) {
                     $match = $item;
                     break;
                 }
             }
         }
         if (isset($match)) {
             break;
         }
     }
     return $match;
 }