Ejemplo n.º 1
0
 public static function getApplication()
 {
     // check if application object already exists
     if (isset(self::$_application)) {
         return self::$_application;
     }
     // get joomla and application table
     $joomla = JFactory::getApplication();
     $table = YTable::getInstance('application');
     // handle admin
     if ($joomla->isAdmin()) {
         // create application from user state, or search for default
         $id = $joomla->getUserState('com_zooapplication');
         $apps = $table->all(array('order' => 'name'));
         if (isset($apps[$id])) {
             self::$_application = $apps[$id];
         } else {
             if (!empty($apps)) {
                 self::$_application = array_shift($apps);
             }
         }
         return self::$_application;
     }
     // handle site
     if ($joomla->isSite()) {
         // get component params
         $params = $joomla->getParams();
         // create application from menu item params / request
         if ($item_id = YRequest::getInt('item_id')) {
             if ($item = YTable::getInstance('item')->get($item_id)) {
                 self::$_application = $item->getApplication();
             }
         } else {
             if ($category_id = YRequest::getInt('category_id')) {
                 if ($category = YTable::getInstance('category')->get($category_id)) {
                     self::$_application = $category->getApplication();
                 }
             } else {
                 if ($id = YRequest::getInt('app_id')) {
                     self::$_application = $table->get($id);
                 } else {
                     if ($id = $params->get('application')) {
                         self::$_application = $table->get($id);
                     } else {
                         // try to get application from default menu item
                         $menu = JSite::getMenu(true);
                         $default = $menu->getDefault();
                         if (isset($default->component) && $default->component == 'com_zoo') {
                             if ($app_id = $menu->getParams($default->id)->get('application')) {
                                 self::$_application = $table->get($app_id);
                             }
                         }
                     }
                 }
             }
         }
         return self::$_application;
     }
     return null;
 }
Ejemplo n.º 2
0
 public function __construct($default = array())
 {
     parent::__construct($default);
     $this->item_id = JRequest::getInt('item_id');
     // get submission info from Request
     if (!($submission_id = YRequest::getInt('submission_id'))) {
         // else get submission info from menu item
         if ($menu = JSite::getMenu()->getActive()) {
             $this->menu_params = new JParameter($menu->params);
             $submission_id = $this->menu_params->get('submission');
         }
     }
     // set submission
     if ($this->submission = YTable::getInstance('submission')->get($submission_id)) {
         // set application
         $this->application = $this->submission->getApplication();
         // set template
         $this->template = $this->application->getTemplate();
         // set renderer
         $this->renderer = new ItemRenderer();
         $this->renderer->addPath(array($this->template->getPath(), ZOO_SITE_PATH));
     }
 }
Ejemplo n.º 3
0
 public function feed()
 {
     // get request vars
     $category_id = (int) YRequest::getInt('category_id', $this->params->get('category'));
     // get params
     $all_categories = $this->application->getCategoryTree(true);
     // raise warning when category can not be accessed
     if (!isset($all_categories[$category_id])) {
         JError::raiseWarning(500, JText::_('Unable to access category'));
         return;
     }
     $category = $all_categories[$category_id];
     $params = $category ? $category->getParams('site') : $this->application->getParams('frontpage');
     $show_feed_link = $params->get('config.show_feed_link', 0);
     $feed_title = $params->get('config.feed_title', '');
     // init vars
     $document = JFactory::getDocument();
     // raise error when feed is link is disabled
     if (empty($show_feed_link)) {
         JError::raiseError(500, JText::_('Unable to access feed'));
         return;
     }
     // get feed items from category
     $categories = $category->getChildren(true);
     $categories[$category->id] = $category;
     $feed_limit = $this->joomla->getCfg('feed_limit');
     $feed_items = YTable::getInstance('item')->getFromCategory($this->application->id, array_keys($categories), true, null, 'created DESC', 0, $feed_limit);
     // set title
     if ($feed_title) {
         $document->setTitle(html_entity_decode($this->getView()->escape($feed_title)));
     }
     // set feed link
     $document->link = JRoute::_($this->link_base . '&task=category');
     // set renderer
     $renderer = new ItemRenderer();
     $renderer->addPath(array($this->application->getTemplate()->getPath(), ZOO_SITE_PATH));
     foreach ($feed_items as $feed_item) {
         // create feed item
         $item = new JFeedItem();
         $item->title = html_entity_decode($this->getView()->escape($feed_item->name));
         $item->link = JRoute::_(RouteHelper::getItemRoute($feed_item));
         $item->date = $feed_item->created;
         $item->author = $feed_item->getAuthor();
         $item->description = $this->_relToAbs($renderer->render('item.feed', array('item' => $feed_item)));
         // add to feed document
         $document->addItem($item);
     }
 }
Ejemplo n.º 4
0
 public function getItemRoute($item)
 {
     YTable::getInstance('application')->get($item->application_id)->getCategoryTree(true);
     // have we found the link before?
     if (isset(self::$_item_links[$item->id])) {
         return self::$_item_links[$item->id];
     }
     // init vars
     $categories = $item->getRelatedCategoryIds(true);
     $categories = array_filter($categories, create_function('$id', 'return !empty($id);'));
     // build item link
     $link = RouteHelper::LINK_BASE . '&task=item&item_id=' . $item->id;
     // Priority 1: direct link to item
     $itemid = null;
     if ($menu_item = self::_findItem($item->id)) {
         $itemid = $menu_item->id;
     }
     // are we in category view?
     $category_id = null;
     if (!$itemid && (YRequest::getCmd('task') == 'category' || YRequest::getCmd('view') == 'category')) {
         $category_id = (int) YRequest::getInt('category_id', JFactory::getApplication()->getParams()->get('category'));
         $category_id = in_array($category_id, $categories) ? $category_id : null;
     }
     if (!$itemid && !$category_id) {
         $primary = $item->getPrimaryCategory();
         // Priority 2: direct link to primary category
         if ($primary && ($menu_item = self::_findCategory($primary->id))) {
             $itemid = $menu_item->id;
             // Priority 3: find in primary category path
         } else {
             if ($primary && ($menu_item = self::_findInCategoryPath($primary))) {
                 $itemid = $menu_item->id;
             } else {
                 $found = false;
                 foreach ($categories as $category) {
                     // Priority 4: direct link to any related category
                     if ($menu_item = self::_findCategory($category)) {
                         $itemid = $menu_item->id;
                         $found = true;
                         break;
                     }
                 }
                 if (!$found) {
                     $categories = $item->getRelatedCategories(true);
                     foreach ($categories as $category) {
                         // Priority 5: find in any related categorys path
                         if ($menu_item = self::_findInCategoryPath($category)) {
                             $itemid = $menu_item->id;
                             $found = true;
                             break;
                         }
                     }
                 }
                 // Priority 6: link to frontpage
                 if (!$found && ($menu_item = self::_findFrontpage($item->application_id))) {
                     $itemid = $menu_item->id;
                 }
             }
         }
     }
     if ($category_id) {
         $link .= '&category_id=' . $category_id;
     }
     if ($itemid) {
         $link .= '&Itemid=' . $itemid;
         // Priority 7: current item id
     } else {
         if ($menu = JSite::getMenu()->getActive()) {
             $link .= '&Itemid=' . $menu->id;
         }
     }
     // store link for future lookups
     self::$_item_links[$item->id] = $link;
     return $link;
 }
Ejemplo n.º 5
0
 public function save()
 {
     // check for request forgeries
     JRequest::checkToken() or jexit('Invalid Token');
     // init vars
     $post = YRequest::get('post');
     $cid = YRequest::getArray('cid.0', '', 'int');
     $pid = YRequest::getInt('parent_id', 0);
     $now = JFactory::getDate();
     try {
         // get content as raw and filter it
         $post['content'] = YRequest::getVar('content', null, '', 'string', JREQUEST_ALLOWRAW);
         $post['content'] = CommentHelper::filterContentInput($post['content']);
         // get comment table
         $table = YTable::getInstance('comment');
         // get comment or create reply
         if ($cid) {
             $comment = $table->get($cid);
         } else {
             $parent = $table->get($pid);
             $comment = new Comment();
             $comment->item_id = $parent->getItem()->id;
             $comment->user_id = $this->user->id;
             $comment->author = $this->user->name;
             $comment->email = $this->user->email;
             $comment->ip = CommentHelper::getClientIP();
             $comment->created = $now->toMySQL();
             $comment->state = Comment::STATE_APPROVED;
         }
         // bind post data
         $comment->bind($post);
         // save comment
         $table->save($comment);
         // get view
         $view = $this->getView();
         // set view vars
         $view->option = $this->option;
         $view->comment = $comment;
         // display view
         $view->setLayout('_row');
         $view->display();
     } catch (YException $e) {
         // raise error on exception
         echo json_encode(array('group' => 'error', 'title' => JText::_('Error Saving Comment'), 'text' => (string) $e));
     }
 }
Ejemplo n.º 6
0
 public function element()
 {
     $this->_loadGeneralCSS();
     jimport('joomla.html.pagination');
     // get database
     $this->db = JFactory::getDBO();
     // get request vars
     $this->filter_item = YRequest::getInt('item_filter', 0);
     $this->type_filter = YRequest::getArray('type_filter', array());
     $state_prefix = $this->option . '_' . $this->application->id . '.' . ($this->getTask() == 'element' ? 'element' : 'item') . '.';
     $filter_order = $this->joomla->getUserStateFromRequest($state_prefix . 'filter_order', 'filter_order', 'a.created', 'cmd');
     $filter_order_Dir = $this->joomla->getUserStateFromRequest($state_prefix . 'filter_order_Dir', 'filter_order_Dir', 'desc', 'word');
     $filter_category_id = $this->joomla->getUserStateFromRequest($state_prefix . 'filter_category_id', 'filter_category_id', '0', 'string');
     $limit = $this->joomla->getUserStateFromRequest('global.list.limit', 'limit', $this->joomla->getCfg('list_limit'), 'int');
     $limitstart = $this->joomla->getUserStateFromRequest($state_prefix . 'limitstart', 'limitstart', 0, 'int');
     $filter_type = $this->joomla->getUserStateFromRequest($state_prefix . 'filter_type', 'filter_type', '', 'string');
     $filter_author_id = $this->joomla->getUserStateFromRequest($state_prefix . 'filter_author_id', 'filter_author_id', 0, 'int');
     $search = $this->joomla->getUserStateFromRequest($state_prefix . 'search', 'search', '', 'string');
     $search = JString::strtolower($search);
     // is filtered ?
     $this->is_filtered = $filter_category_id != '0' || !empty($filter_type) || !empty($filter_author_id) || !empty($search);
     // in case limit has been changed, adjust limitstart accordingly
     $limitstart = $limit != 0 ? floor($limitstart / $limit) * $limit : 0;
     $table = YTable::getInstance('item');
     $this->users = $table->getUsers($this->application->id);
     $this->groups = ZooHelper::getGroups();
     // get data from the table
     $where = array();
     // application filter
     $where[] = 'a.application_id = ' . (int) $this->application->id;
     // category filter
     if ($filter_category_id > 0) {
         $where[] = 'ci.category_id = ' . (int) $filter_category_id;
     } else {
         if ($filter_category_id === '') {
             $where[] = 'ci.item_id IS NULL';
         }
     }
     // type filter
     if (!empty($this->type_filter)) {
         $where[] = 'a.type IN ("' . implode('", "', $this->type_filter) . '")';
     } else {
         if (!empty($filter_type)) {
             $where[] = 'a.type = "' . (string) $filter_type . '"';
         }
     }
     // item filter
     if ($this->filter_item > 0) {
         $where[] = 'a.id != ' . (int) $this->filter_item;
     }
     // author filter
     if ($filter_author_id > 0) {
         $where[] = 'a.created_by = ' . (int) $filter_author_id;
     }
     if ($search) {
         $where[] = 'LOWER(a.name) LIKE ' . $this->db->Quote('%' . $this->db->getEscaped($search, true) . '%', false);
     }
     // access filter
     $where[] = 'a.access <= ' . (int) $this->user->get('aid', 0);
     // state filter
     $where[] = 'a.state = 1';
     $options = array('select' => 'DISTINCT a.*', 'from' => $table->getTableName() . ' AS a LEFT JOIN ' . ZOO_TABLE_CATEGORY_ITEM . ' AS ci ON a.id = ci.item_id', 'conditions' => array(implode(' AND ', $where)), 'order' => $filter_order . ' ' . $filter_order_Dir);
     $this->items = $table->all($limit > 0 ? array_merge($options, array('offset' => $limitstart, 'limit' => $limit)) : $options);
     $this->items = array_merge($this->items);
     $this->pagination = new JPagination($table->count($options), $limitstart, $limit);
     // category select
     $options = array();
     $options[] = JHTML::_('select.option', '0:0', '- ' . JText::_('Select Category') . ' -');
     $options[] = JHTML::_('select.option', '', '- ' . JText::_('uncategorized') . ' -');
     $this->lists['select_category'] = JHTML::_('zoo.categorylist', $this->application, $options, 'filter_category_id', 'class="inputbox auto-submit"', 'value', 'text', $filter_category_id);
     // type select
     $options = array(JHTML::_('select.option', '0', '- ' . JText::_('Select Type') . ' -'));
     $this->lists['select_type'] = JHTML::_('zoo.typelist', $options, 'filter_type', 'class="inputbox auto-submit"', 'value', 'text', $filter_type, false, false, $this->type_filter);
     // author select
     $options = array(JHTML::_('select.option', '0', '- ' . JText::_('Select Author') . ' -'));
     $this->lists['select_author'] = JHTML::_('zoo.itemauthorlist', $options, 'filter_author_id', 'class="inputbox auto-submit"', 'value', 'text', $filter_author_id);
     // table ordering and search filter
     $this->lists['order_Dir'] = $filter_order_Dir;
     $this->lists['order'] = $filter_order;
     $this->lists['search'] = $search;
     $this->addViewPath(ZOO_ADMIN_PATH . '/views/item/');
     $view = $this->getView('', '', '', array('base_path' => ZOO_ADMIN_PATH));
     $view->setLayout('element')->display();
 }
Ejemplo n.º 7
0
 public function callElement()
 {
     // get request vars
     $element_identifier = YRequest::getString('elm_id', '');
     $item_id = YRequest::getInt('item_id', 0);
     $type = YRequest::getString('type', '');
     $this->method = YRequest::getCmd('method', '');
     $this->args = YRequest::getVar('args', array(), 'default', 'array');
     JArrayHelper::toString($this->args);
     // load element
     if ($item_id) {
         $item = YTable::getInstance('item')->get($item_id);
     } elseif (!empty($type)) {
         $item = new Item();
         $item->application_id = $this->application->id;
         $item->type = $type;
     }
     // execute callback method
     if ($element = $item->getElement($element_identifier)) {
         echo $element->callback($this->method, $this->args);
     }
 }
Ejemplo n.º 8
0
// add css, js
JHTML::script('jquery-ui-1.8.6.custom.min.js', ZOO_ADMIN_URI . 'libraries/jquery/');
JHTML::stylesheet('jquery-ui-1.8.6.custom.css', ZOO_ADMIN_URI . 'libraries/jquery/');
JHTML::script('accordionmenu.js', ZOO_ADMIN_URI . 'assets/js/');
JHTML::script('placeholder.js', ZOO_ADMIN_URI . 'assets/js/');
JHTML::script('jquery.pnotify.js', ZOO_ADMIN_URI . 'libraries/jquery/plugins/notifier/');
JHTML::stylesheet('jquery.pnotify.default.css', ZOO_ADMIN_URI . 'libraries/jquery/plugins/notifier/');
JHTML::script('default.js', ZOO_ADMIN_URI . 'assets/js/');
JHTML::stylesheet('ui.css', ZOO_ADMIN_URI . 'assets/css/');
JHTMLBehavior::modal();
// init vars
$controller = YRequest::getWord('controller');
$task = YRequest::getWord('task');
$group = YRequest::getString('group');
// change application
if ($id = YRequest::getInt('changeapp')) {
    JFactory::getApplication()->setUserState('com_zooapplication', $id);
}
// load application
$application = Zoo::getApplication();
// set default controller
if (!$controller) {
    $controller = $application ? 'item' : 'new';
    YRequest::setVar('controller', $controller);
}
// set toolbar button include path
$toolbar = JToolBar::getInstance('toolbar');
$toolbar->addButtonPath(ZOO_ADMIN_PATH . '/joomla/button');
// build menu
$menu = YMenu::getInstance('nav');
// add "app" menu items
Ejemplo n.º 9
0
 public function facebookAuthenticate()
 {
     // init vars
     $item_id = YRequest::getInt('item_id', 0);
     $item = YTable::getInstance('item')->get($item_id);
     // get facebook client
     $connection = CommentHelper::getFacebookClient();
     if ($connection) {
         $code = YRequest::getString('code', '');
         $uri = new JURI();
         $redirect = $uri->root() . $this->link_base . '&controller=comment&task=facebookauthenticate&item_id=' . $item_id;
         $url = $connection->getAccessTokenURL($code, $redirect);
         $http = new HttpHelper();
         $result = $http->get($url, array('ssl_verifypeer' => false));
         $token = str_replace('access_token=', '', $result['body']);
         $_SESSION['facebook_access_token'] = $token;
     }
     $redirect = JRoute::_(RouteHelper::getItemRoute($item));
     $this->setRedirect($redirect);
 }