Example #1
0
 public function export()
 {
     if (!($this->_application = Zoo::getApplication())) {
         throw new ExportHelperException('No application selected.');
     }
     // export frontpage
     $frontpage = new Category();
     $frontpage->name = 'Root';
     $frontpage->alias = '_root';
     $frontpage->description = $this->_application->description;
     // export categories
     $categories = $this->_application->getCategories();
     $categories[0] = $frontpage;
     foreach ($categories as $category) {
         $this->_addCategory($this->_categoryToXML($category, $categories));
     }
     $this->categories = $categories;
     // export items
     $types = $this->_application->getTypes();
     $item_table = YTable::getInstance('item');
     foreach ($types as $type) {
         $items = $item_table->getByType($type->id, $this->_application->id);
         foreach ($items as $key => $item) {
             $this->_addItem($type->name, $this->_itemToXML($item));
             $item->unsetElementData();
             unset($items[$key]);
         }
     }
     return parent::export();
 }
Example #2
0
 public function save()
 {
     // check for request forgeries
     YRequest::checkToken() or jexit('Invalid Token');
     // init vars
     $post = YRequest::get('post');
     try {
         // bind post
         $this->application->bind($post, array('params'));
         // set params
         $params = $this->application->getParams()->remove('global.')->set('group', @$post['group'])->set('template', @$post['template'])->set('global.config.', @$post['params']['config'])->set('global.template.', @$post['params']['template']);
         if (isset($post['addons']) && is_array($post['addons'])) {
             foreach ($post['addons'] as $addon => $value) {
                 $params->set("global.{$addon}.", $value);
             }
         }
         $this->application->params = $params->toString();
         // save application
         YTable::getInstance('application')->save($this->application);
         // set redirect
         $msg = JText::_('Application Saved');
         $link = $this->link_base . '&changeapp=' . $this->application->id;
     } catch (YException $e) {
         // raise notice on exception
         JError::raiseNotice(0, JText::_('Error Saving Application') . ' (' . $e . ')');
         // set redirect
         $msg = null;
         $link = $this->baseurl . '&task=add';
     }
     $this->setRedirect($link, $msg);
 }
Example #3
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;
 }
Example #4
0
 public static function renderComments($view, $item)
 {
     if ($item->getApplication()->isCommentsEnabled()) {
         // get application params
         $params = new YParameter();
         $params->loadArray(Zoo::getApplication()->getParams()->get('global.comments.'));
         if ($params->get('twitter_enable') && !function_exists('curl_init')) {
             JError::raiseWarning(500, JText::_('To use Twitter, CURL needs to be enabled in your php settings.'));
             $params->set('twitter_enable', false);
         }
         // get active author
         $active_author = self::activeAuthor();
         // get comments count
         $params->set('count', self::countComments($item));
         // get comment content from session
         $content = JFactory::getSession()->get('com_zoo.comment.content');
         $params->set('content', $content);
         // get comments and build tree
         $comments = YTable::getInstance('comment')->getCommentsForItem($item->id, $params->get('order', 'ASC'), $active_author);
         $comments = self::_buildTree($comments, $params->get('max_depth', 5));
         $comments = self::_buildComments($view, $comments, 0, $params);
         if ($item->isCommentsEnabled() || count($comments)) {
             // create comments html
             return $view->partial('comments', compact('item', 'active_author', 'comments', 'params'));
         }
     }
     return null;
 }
Example #5
0
 public function count($application_id)
 {
     $select = 'DISTINCT a.name';
     $from = $this->getTableName() . " AS a, " . ZOO_TABLE_ITEM . " AS b USE INDEX (ID_APPLICATION_INDEX)";
     $conditions = array("a.item_id = b.id AND b.application_id = " . (int) $application_id);
     $options = compact('select', 'from', 'conditions');
     return parent::count($options);
 }
Example #6
0
 function fetchElement($name, $value, &$node, $control_name)
 {
     JHTML::_('behavior.modal', 'a.modal');
     JHTML::stylesheet('zoosubmission.css', ZOO_ADMIN_URI . '/joomla/elements/');
     JHTML::script('zoosubmission.js', ZOO_ADMIN_URI . '/joomla/elements/');
     // init vars
     $params = $this->_parent;
     $table = YTable::getInstance('application');
     $show_types = $node->attributes('types');
     // create application/category select
     $submissions = array();
     $types = array();
     $app_options = array(JHTML::_('select.option', '', '- ' . JText::_('Select Application') . ' -'));
     foreach ($table->all(array('order' => 'name')) as $app) {
         // application option
         $app_options[$app->id] = JHTML::_('select.option', $app->id, $app->name);
         // create submission select
         $submission_options = array();
         foreach ($app->getSubmissions() as $submission) {
             $submission_options[$submission->id] = JHTML::_('select.option', $submission->id, $submission->name);
             if ($show_types) {
                 $type_options = array();
                 $type_objects = $submission->getSubmittableTypes();
                 if (!count($type_objects)) {
                     unset($submission_options[$submission->id]);
                     continue;
                 }
                 foreach ($submission->getTypes() as $type) {
                     $type_options[] = JHTML::_('select.option', $type->id, $type->name);
                 }
                 $attribs = 'class="type submission-' . $submission->id . ' app-' . $app->id . '" role="' . $control_name . '[type]"';
                 $types[] = JHTML::_('select.genericlist', $type_options, $control_name . '[type]', $attribs, 'value', 'text', $params->get('type'));
             }
         }
         if (!count($submission_options)) {
             unset($app_options[$app->id]);
             continue;
         }
         $attribs = 'class="submission app-' . $app->id . '" role="' . $control_name . '[submission]"';
         $submissions[] = JHTML::_('select.genericlist', $submission_options, $control_name . '[submission]', $attribs, 'value', 'text', $params->get('submission'));
     }
     // create html
     $html[] = '<div id="' . $name . '" class="zoo-submission">';
     // create application html
     $html[] = JHTML::_('select.genericlist', $app_options, $control_name . '[' . $name . ']', 'class="application"', 'value', 'text', $value);
     // create submission html
     $html[] = '<div class="submissions">' . implode("\n", $submissions) . '</div>';
     // create types html
     if ($show_types) {
         $html[] = '<div class="types">' . implode("\n", $types) . '</div>';
     }
     $html[] = '</div>';
     $javascript = 'jQuery("#' . $name . '").ZooSubmission();';
     $javascript = "<script type=\"text/javascript\">\n// <!--\n{$javascript}\n// -->\n</script>\n";
     return implode("\n", $html) . $javascript;
 }
Example #7
0
 public function export()
 {
     $db = YDatabase::getInstance();
     $query = "SELECT * FROM #__sections" . " WHERE scope='content'";
     $sections = $db->queryObjectList($query);
     // get category table
     $category_table = YTable::getInstance('category');
     // get item table
     $item_table = YTable::getInstance('item');
     // get image path
     $image_path = JComponentHelper::getParams('com_media')->get('image_path');
     foreach ($sections as $section) {
         $attributes = array();
         foreach (self::$category_attributes as $attribute) {
             if (isset($section->{$attribute})) {
                 $attributes[$attribute] = $section->{$attribute};
             }
         }
         $category_xml = $this->_buildCategory($section->alias, $section->title, $attributes);
         if ($section->image) {
             $this->_attachCategoryImage($category_xml, $image_path . '/' . $section->image, 'Image');
         }
         $this->_addCategory($category_xml);
         $query = "SELECT * FROM #__categories WHERE section = " . $section->id;
         $joomla_categories = $db->queryObjectList($query);
         foreach ($joomla_categories as $joomla_category) {
             $attributes = array();
             foreach (self::$category_attributes as $attribute) {
                 if (isset($joomla_category->{$attribute})) {
                     $attributes[$attribute] = $joomla_category->{$attribute};
                 }
             }
             $attributes['parent'] = $section->alias;
             $category_xml = $this->_buildCategory($joomla_category->alias, $joomla_category->title, $attributes);
             if ($joomla_category->image) {
                 $this->_attachCategoryImage($category_xml, $image_path . '/' . $joomla_category->image, 'Image');
             }
             $this->_addCategory($category_xml);
             $query = "SELECT * FROM #__content WHERE catid =" . $joomla_category->id;
             $articles = $db->queryObjectList($query);
             foreach ($articles as $article) {
                 if ($article->state != -2) {
                     $this->_addItem(JText::_('Joomla article'), $this->_articleToXML($article, $joomla_category->alias));
                 }
             }
         }
     }
     $query = "SELECT * FROM #__content WHERE catid = 0";
     $articles = $db->queryObjectList($query);
     foreach ($articles as $article) {
         if ($article->state != -2) {
             $this->_addItem(JText::_('Joomla article'), $this->_articleToXML($article, 0));
         }
     }
     return parent::export();
 }
Example #8
0
 public function render($params = array())
 {
     $category_ids = $this->_data->get('category', array());
     $category_links = array();
     $categories = YTable::getInstance('category')->getById($category_ids, true);
     foreach ($categories as $category) {
         $category_links[] = '<a href="' . RouteHelper::getCategoryRoute($category) . '">' . $category->name . '</a>';
     }
     return ElementHelper::applySeparators($params['separated_by'], $category_links);
 }
Example #9
0
 public function delete($object)
 {
     // get database
     $db = $this->getDBO();
     // update childrens parent category
     $query = "UPDATE " . $this->getTableName() . " SET parent=" . $object->parent . " WHERE parent=" . $object->id;
     $db->query($query);
     // delete category to item relations
     CategoryHelper::deleteCategoryItemRelations($object->id);
     return parent::delete($object);
 }
Example #10
0
 public static function getLatestComments($app, $categories, $limit)
 {
     // build where condition
     $where = array('b.application_id = ' . (int) $app->id);
     $where[] = 'a.state = ' . 1;
     $where[] = is_array($categories) ? "c.category_id IN (" . implode(",", $categories) . ")" : "c.category_id = " . $categories;
     // build query options
     $options = array('select' => 'a.*, b.application_id', 'from' => ZOO_TABLE_COMMENT . ' AS a' . ' LEFT JOIN ' . ZOO_TABLE_ITEM . ' AS b ON a.item_id = b.id' . ' LEFT JOIN ' . ZOO_TABLE_CATEGORY_ITEM . ' AS c ON b.id = c.item_id', 'conditions' => array(implode(' AND ', $where)), 'order' => 'created DESC', 'group' => 'a.id', 'offset' => 0, 'limit' => $limit);
     // query comment table
     return YTable::getInstance('comment')->all($options);
 }
Example #11
0
 public function save($object)
 {
     if ($object->name == '') {
         throw new SubmissionTableException('Invalid name');
     }
     if ($object->alias == '' || preg_match('/[^\\x{00C0}-\\x{00D6}x{00D8}-\\x{00F6}x{00F8}-\\x{00FF}x{0370}-\\x{1FFF}a-z0-9\\-]/u', $object->alias)) {
         throw new SubmissionTableException('Invalid slug');
     }
     if (SubmissionHelper::checkAliasExists($object->alias, $object->id)) {
         throw new SubmissionTableException('Slug already exists, please choose a unique slug');
     }
     return parent::save($object);
 }
Example #12
0
 public static function getUniqueAlias($id, $alias = '')
 {
     if (empty($alias) && $id) {
         $alias = JFilterOutput::stringURLSafe(YTable::getInstance('item')->get($id)->name);
     }
     if (!empty($alias)) {
         $i = 2;
         $new_alias = $alias;
         while (self::checkAliasExists($new_alias, $id)) {
             $new_alias = $alias . '-' . $i++;
         }
         return $new_alias;
     }
     return $alias;
 }
Example #13
0
 public function delete($object)
 {
     // delete related categories
     $table = YTable::getInstance('category');
     $categories = $table->getAll($object->id);
     foreach ($categories as $category) {
         $table->delete($category);
     }
     // delete related items
     $table = YTable::getInstance('item');
     $items = $table->findAll($object->id);
     foreach ($items as $item) {
         $table->delete($item);
     }
     return parent::delete($object);
 }
Example #14
0
 public static function getItemsByType($app, $type, $ordering, $limit)
 {
     // init vars
     $table = YTable::getInstance('item');
     // get database
     $db = $table->getDBO();
     // get user from session, if not set
     $user = JFactory::getUser();
     // get user access id
     $access_id = $user->get('aid', 0);
     // get date
     $date = JFactory::getDate();
     $now = $db->Quote($date->toMySQL());
     $null = $db->Quote($db->getNullDate());
     // set query options
     $conditions = "a.application_id = " . (int) $app->id . " AND a.access <= " . (int) $access_id . " AND a.state = 1" . " AND a.type = '?'" . " AND (a.publish_up = " . $null . " OR a.publish_up <= " . $now . ")" . " AND (a.publish_down = " . $null . " OR a.publish_down >= " . $now . ")";
     $options = array('select' => 'a.*', 'from' => ZOO_TABLE_ITEM . ' AS a', 'conditions' => array($conditions, $type), 'order' => self::getOrder($ordering), 'limit' => $limit);
     return $table->all($options);
 }
Example #15
0
 public function update()
 {
     // init vars
     $old = YRequest::getString('old');
     $new = YRequest::getString('new');
     $msg = null;
     try {
         $app = Zoo::getApplication();
         // update tag
         if (!empty($new) && $old != $new) {
             YTable::getInstance('tag')->update($app->id, $old, $new);
             // set redirect message
             $msg = JText::_('Tag Updated Successfully');
         }
     } catch (YException $e) {
         // raise notice on exception
         JError::raiseWarning(0, JText::_('Error Updating Tag') . ' (' . $e . ')');
     }
     $this->setRedirect($this->baseurl, $msg);
 }
Example #16
0
 public static function buildTagCloud($app, $params)
 {
     // get tags
     $tags = YTable::getInstance('tag')->getAll($app->id, null, null, 'items DESC', null, $params->get('count', 10), true);
     if (count($tags)) {
         // init vars
         $min_count = $tags[count($tags) - 1]->items;
         $max_count = $tags[0]->items;
         $font_span = ($max_count - $min_count) / 100;
         $font_class_span = (self::MAX_FONT_WEIGHT - self::MIN_FONT_WEIGHT) / 100;
         $menu_item = $params->get('menu_item', 0);
         $itemid = $menu_item ? '&Itemid=' . $menu_item : '';
         // attach font size, href
         foreach ($tags as $tag) {
             $tag->weight = $font_span ? round(self::MIN_FONT_WEIGHT + ($tag->items - $min_count) / $font_span * $font_class_span) : 1;
             $tag->href = $menu_item ? sprintf('index.php?option=com_zoo&task=tag&tag=%s&app_id=%d%s', $tag->name, $app->id, $itemid) : RouteHelper::getTagRoute($app->id, $tag->name);
         }
         self::orderTags($tags, $params->get('order'));
         return $tags;
     }
     return array();
 }
Example #17
0
 public function save()
 {
     // check for request forgeries
     YRequest::checkToken() or jexit('Invalid Token');
     // init vars
     $post = YRequest::get('post');
     $post['description'] = YRequest::getVar('description', '', 'post', 'string', JREQUEST_ALLOWRAW);
     try {
         // bind post
         $this->application->bind($post, array('params'));
         // set params
         $this->application->params = $this->application->getParams()->remove('content.')->remove('config.')->remove('template.')->set('content.', @$post['params']['content'])->set('config.', @$post['params']['config'])->set('template.', @$post['params']['template'])->toString();
         // save application
         YTable::getInstance('application')->save($this->application);
         // set redirect message
         $msg = JText::_('Frontpage Saved');
     } catch (YException $e) {
         // raise notice on exception
         JError::raiseNotice(0, JText::_('Error Saving Frontpage') . ' (' . $e . ')');
         $msg = null;
     }
     $this->setRedirect($this->baseurl, $msg);
 }
Example #18
0
 public function saveElements()
 {
     // check for request forgeries
     YRequest::checkToken() or jexit('Invalid Token');
     // init vars
     $post = YRequest::get('post');
     $cid = YRequest::getArray('cid.0', '', 'string');
     try {
         // get type
         $type = $this->application->getType($cid);
         // save elements
         ElementHelper::saveElements($post, $type);
         // save type
         $type->save();
         // reset related item search data
         $table = YTable::getInstance('item');
         $items = $table->getByType($type->id, $this->application->id);
         foreach ($items as $item) {
             $table->save($item);
         }
         $msg = JText::_('Elements Saved');
     } catch (YException $e) {
         JError::raiseNotice(0, JText::_('Error Saving Elements') . ' (' . $e . ')');
         $this->_task = 'applyelements';
         $msg = null;
     }
     switch ($this->getTask()) {
         case 'applyelements':
             $link = $this->baseurl . '&task=editelements&cid[]=' . $type->id;
             break;
         case 'saveelements':
         default:
             $link = $this->baseurl . '&task=types';
             break;
     }
     $this->setRedirect($link, $msg);
 }
Example #19
0
 public function vote($vote = null)
 {
     // init vars
     $max_stars = $this->_config->get('stars');
     $allow_vote = $this->_config->get('allow_vote');
     $db = YDatabase::getInstance();
     $user = JFactory::getUser();
     $date = JFactory::getDate();
     $vote = (int) $vote;
     for ($i = 1; $i <= $max_stars; $i++) {
         $stars[] = $i;
     }
     if ($allow_vote > $user->get('aid', 0)) {
         return json_encode(array('value' => 0, 'message' => JText::_('NOT_ALLOWED_TO_VOTE')));
     }
     if (in_array($vote, $stars) && isset($_SERVER['REMOTE_ADDR']) && ($ip = $_SERVER['REMOTE_ADDR'])) {
         // check if ip already exists
         $query = 'SELECT *' . ' FROM ' . ZOO_TABLE_RATING . ' WHERE element_id = ' . $db->Quote($this->identifier) . ' AND item_id = ' . (int) $this->_item->id . ' AND ip = ' . $db->Quote($ip);
         $db->query($query);
         // voted already
         if ($db->getNumRows()) {
             return json_encode(array('value' => 0, 'message' => JText::_("You've already voted")));
         }
         // insert vote
         $query = "INSERT INTO " . ZOO_TABLE_RATING . " SET element_id = " . $db->Quote($this->identifier) . " ,item_id = " . (int) $this->_item->id . " ,user_id = " . (int) $user->id . " ,value = " . (int) $vote . " ,ip = " . $db->Quote($ip) . " ,created = " . $db->Quote($date->toMySQL());
         // execute query
         $db->query($query);
         // calculate rating/votes
         $query = 'SELECT AVG(value) AS rating, COUNT(id) AS votes' . ' FROM ' . ZOO_TABLE_RATING . ' WHERE element_id = ' . $db->Quote($this->identifier) . ' AND item_id = ' . $this->_item->id . ' GROUP BY item_id';
         if ($res = $db->queryAssoc($query)) {
             $this->_data->set('votes', $res['votes']);
             $this->_data->set('value', $res['rating']);
         } else {
             $this->_data->set('votes', 0);
             $this->_data->set('value', 0);
         }
     }
     //save item
     YTable::getInstance('item')->save($this->getItem());
     return json_encode(array('value' => intval($this->getRating() / $max_stars * 100), 'message' => sprintf(JText::_('%s rating from %s votes'), $this->getRating(), $this->_data->get('votes'))));
 }
Example #20
0
 protected function _editTrustedMode($enabled)
 {
     // check for request forgeries
     YRequest::checkToken() or jexit('Invalid Token');
     // init vars
     $cid = YRequest::getArray('cid', array(), 'int');
     if (count($cid) < 1) {
         JError::raiseError(500, JText::_('Select a submission to enable/disable Trusted Mode'));
     }
     try {
         // get item table
         $table = YTable::getInstance('submission');
         // update item state
         foreach ($cid as $id) {
             $submission = $table->get($id);
             $submission->params = $submission->getParams()->set('trusted_mode', $enabled)->toString();
             $table->save($submission);
         }
     } catch (YException $e) {
         // raise notice on exception
         JError::raiseNotice(0, JText::_('Error enabling/disabling Submission Trusted Mode') . ' (' . $e . ')');
     }
     $this->setRedirect($this->baseurl);
 }
Example #21
0
<?php

/**
* @package   ZOO Comment
* @file      list-v.php
* @version   2.3.0
* @author    YOOtheme http://www.yootheme.com
* @copyright Copyright (C) 2007 - 2011 YOOtheme GmbH
* @license   http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
// include css
JHTML::stylesheet('style.css', JURI::base() . 'modules/mod_zoocomment/tmpl/list-v/');
$count = count($comments);
$table = YTable::getInstance('item');
?>

<div class="zoo-comment list-v">

	<?php 
if ($count) {
    ?>
	
		<ul>
			<?php 
    $i = 0;
    foreach ($comments as $comment) {
        ?>
			
				<?php 
Example #22
0
 public function getItems($published = false, $user = null, $orderby = '')
 {
     if (empty($this->_items)) {
         $this->_items = YTable::getInstance('item')->getFromCategory($this->application_id, $this->id, $published, $user, $orderby);
     }
     return $this->_items;
 }
Example #23
0
 public function export()
 {
     $db = YDatabase::getInstance();
     $user = JFactory::getUser();
     // get mtree categories
     $query = "SELECT *" . ", cat_parent as parent" . ", cat_created as created" . ", cat_published as published" . ", cat_name as name" . ", cat_desc as description" . ", cat_image as image" . " FROM #__mt_cats" . " WHERE cat_id != 0" . " ORDER BY cat_parent, ordering";
     $categories = $db->queryObjectList($query, 'cat_id');
     // get category table
     $category_table = YTable::getInstance('category');
     // get item table
     $item_table = YTable::getInstance('item');
     // sanatize category aliases
     $aliases = array();
     foreach ($categories as $category) {
         $i = 2;
         $alias = YString::sluggify($category->alias);
         if (empty($alias)) {
             $alias = YString::sluggify($category->name);
         }
         $category->alias = $alias;
         while (in_array($alias, $aliases)) {
             $alias = $category->alias . '-' . $i++;
         }
         $category->alias = $alias;
         // remember used aliases to ensure unique aliases
         $aliases[] = $category->alias;
     }
     // get image and file path
     $this->image_path = JComponentHelper::getParams('com_media')->get('image_path');
     $this->image_path = trim($this->image_path, '\\/') . '/';
     $this->file_path = JComponentHelper::getParams('com_media')->get('file_path');
     $this->file_path = trim($this->file_path, '\\/') . '/';
     require_once JPATH_ADMINISTRATOR . '/components/com_mtree/config.mtree.class.php';
     $mtconf = new mtConfig($db);
     $this->category_image_path = $mtconf->get('relative_path_to_cat_original_image');
     $this->category_image_path = trim($this->category_image_path, '\\/') . '/';
     $this->listing_image_path = $mtconf->get('relative_path_to_listing_original_image');
     $this->listing_image_path = trim($this->listing_image_path, '\\/') . '/';
     $this->attachement_path = $mtconf->get('relative_path_to_attachments');
     $this->attachement_path = trim($this->attachement_path, '\\/') . '/';
     $this->import_path_category_images = JPATH_ROOT . '/' . $this->image_path . 'zoo/mtree_import/cats/';
     $this->import_path_item_images = JPATH_ROOT . '/' . $this->image_path . 'zoo/mtree_import/items/';
     $this->import_path_attachments = JPATH_ROOT . '/' . $this->image_path . 'zoo/mtree_import/attachments/';
     $this->import_path_gallery = JPATH_ROOT . '/' . $this->image_path . 'zoo/mtree_import/gallery/';
     // create import folders
     if (!JFolder::exists($this->import_path_category_images)) {
         JFolder::create($this->import_path_category_images);
     }
     if (!JFolder::exists($this->import_path_item_images)) {
         JFolder::create($this->import_path_item_images);
     }
     if (!JFolder::exists($this->import_path_attachments)) {
         JFolder::create($this->import_path_attachments);
     }
     if (!JFolder::exists($this->import_path_gallery)) {
         JFolder::create($this->import_path_gallery);
     }
     // export categories
     foreach ($categories as $category) {
         // assign attributes
         $attributes = array();
         foreach (self::$category_attributes as $attribute) {
             if (isset($category->{$attribute})) {
                 $attributes[$attribute] = $category->{$attribute};
             }
         }
         // sanatize parent
         if ($category->parent && isset($categories[$category->parent])) {
             $attributes['parent'] = $categories[$category->parent]->alias;
         }
         // add category
         $category_xml = $this->_buildCategory($category->alias, $category->name, $attributes);
         if ($category->image) {
             $old_file_name = JPATH_ROOT . '/' . $this->category_image_path . $category->image;
             $file_info = pathinfo($category->image);
             $file_name = $this->import_path_category_images . $category->image;
             $i = 2;
             while (JFile::exists($file_name)) {
                 $file_name = $this->import_path_category_images . $file_info['filename'] . '-' . $i++ . '.' . $file_info['extension'];
             }
             if (JFile::copy($old_file_name, $file_name)) {
                 $image = trim(str_replace('\\', '/', preg_replace('/^' . preg_quote(JPATH_ROOT, '/') . '/i', '', $file_name)), '/');
                 $this->_attachCategoryImage($category_xml, $image, 'Image');
             }
         }
         $this->_addCategory($category_xml);
     }
     // get mtree items
     $query = "SELECT *, link_id as id" . ", link_name as name" . ", link_desc as description" . ", user_id as created_by" . ", link_hits as hits" . ", link_published as published" . ", link_created as created" . ", link_modified as modified" . " FROM #__mt_links";
     $items = $db->queryObjectList($query, 'link_id');
     // sanatize item aliases
     $aliases = array();
     foreach ($items as $item) {
         $i = 2;
         $alias = YString::sluggify($item->alias);
         while (in_array($alias, $aliases)) {
             $alias = YString::sluggify($item->alias) . '-' . $i++;
         }
         $item->alias = $alias;
         // remember used aliases to ensure unique aliases
         $aliases[] = $item->alias;
     }
     // export items
     foreach ($items as $item) {
         $this->_addItem('mtree', $this->_itemToXML($item, $categories));
     }
     return parent::export();
 }
Example #24
0
 public static function importCSV($file, $type = '', $contains_headers = false, $field_separator = ',', $field_enclosure = '"', $element_assignment = array())
 {
     // get application
     if ($application = Zoo::getApplication()) {
         if ($type_obj = $application->getType($type)) {
             $c = 0;
             $assignments = array();
             foreach ($element_assignment as $column => $value) {
                 if (!empty($value[$type])) {
                     $name = $value[$type];
                     $assignments[$name][] = $column;
                 }
             }
             if (!isset($assignments['_name'])) {
                 throw new ImportHelperException('No item name was assigned.');
             }
             if (($handle = fopen($file, "r")) !== FALSE) {
                 $item_table = YTable::getInstance('item');
                 $category_table = YTable::getInstance('category');
                 $user_id = JFactory::getUser()->get('id');
                 $now = JFactory::getDate();
                 $row = 0;
                 $app_categories = $application->getCategories();
                 $app_categories = array_map(create_function('$cat', 'return $cat->name;'), $app_categories);
                 $elements = $type_obj->getElements();
                 while (($data = fgetcsv($handle, 0, $field_separator, $field_enclosure)) !== FALSE) {
                     if (!($contains_headers && $row == 0)) {
                         $item = new Item();
                         $item->application_id = $application->id;
                         $item->type = $type;
                         // store created by
                         $item->created_by = $user_id;
                         // set created
                         $item->created = $now->toMySQL();
                         // store modified_by
                         $item->modified_by = $user_id;
                         // set modified
                         $item->modified = $now->toMySQL();
                         // store element_data and item name
                         $item_categories = array();
                         foreach ($assignments as $assignment => $columns) {
                             $column = current($columns);
                             switch ($assignment) {
                                 case '_name':
                                     $item->name = $data[$column];
                                     break;
                                 case '_created_by_alias':
                                     $item->created_by_alias = $data[$column];
                                     break;
                                 case '_created':
                                     if (!empty($data[$column])) {
                                         $item->created = $data[$column];
                                     }
                                     break;
                                 default:
                                     if (substr($assignment, 0, 9) == '_category') {
                                         foreach ($columns as $column) {
                                             $item_categories[] = $data[$column];
                                         }
                                     } else {
                                         if (isset($elements[$assignment])) {
                                             $elements[$assignment]->unsetData();
                                             switch ($elements[$assignment]->getElementType()) {
                                                 case 'text':
                                                 case 'textarea':
                                                 case 'link':
                                                 case 'email':
                                                 case 'date':
                                                     $element_data = array();
                                                     foreach ($columns as $column) {
                                                         if (!empty($data[$column])) {
                                                             $element_data[$column] = array('value' => $data[$column]);
                                                         }
                                                     }
                                                     $elements[$assignment]->bindData($element_data);
                                                     break;
                                                 case 'gallery':
                                                     $data[$column] = trim($data[$column], '/\\');
                                                     $elements[$assignment]->bindData(array('value' => $data[$column]));
                                                     break;
                                                 case 'image':
                                                 case 'download':
                                                     $elements[$assignment]->bindData(array('file' => $data[$column]));
                                                     break;
                                                 case 'googlemaps':
                                                     $elements[$assignment]->bindData(array('location' => $data[$column]));
                                                     break;
                                             }
                                         }
                                     }
                                     break;
                             }
                         }
                         $elements_string = '<?xml version="1.0" encoding="UTF-8"?><elements>';
                         foreach ($elements as $element) {
                             $elements_string .= $element->toXML();
                         }
                         $elements_string .= '</elements>';
                         $item->elements = $elements_string;
                         $item->alias = YString::sluggify($item->name);
                         if (empty($item->alias)) {
                             $item->alias = '42';
                         }
                         // set a valid category alias
                         while (ItemHelper::checkAliasExists($item->alias)) {
                             $item->alias .= '-2';
                         }
                         if (!empty($item->name)) {
                             try {
                                 $item_table->save($item);
                                 $item_id = $item->id;
                                 $item->unsetElementData();
                                 // store categories
                                 foreach ($item_categories as $category_name) {
                                     if (!in_array($category_name, $app_categories)) {
                                         $category = new Category();
                                         $category->application_id = $application->id;
                                         $category->name = $category_name;
                                         $category->parent = 0;
                                         $category->alias = YString::sluggify($category_name);
                                         // set a valid category alias
                                         while (CategoryHelper::checkAliasExists($category->alias)) {
                                             $category->alias .= '-2';
                                         }
                                         try {
                                             $category_table->save($category);
                                             $related_categories[$category->id] = $category->name;
                                             $app_categories[$category->id] = $category->name;
                                         } catch (CategoryTableException $e) {
                                         }
                                     } else {
                                         $related_categories = array_filter($app_categories, create_function('$cat', 'return $cat=="' . $category_name . '";'));
                                     }
                                     // add category to item relations
                                     if (!empty($related_categories)) {
                                         CategoryHelper::saveCategoryItemRelations($item_id, array_keys($related_categories));
                                     }
                                 }
                             } catch (ItemTableException $e) {
                             }
                         }
                     }
                     $row++;
                 }
                 fclose($handle);
                 return true;
             } else {
                 throw new ImportHelperException('Could not open csv file.');
             }
         } else {
             throw new ImportHelperException('Could not find type.');
         }
     }
     throw new ImportHelperException('No application to import too.');
 }
Example #25
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;
 }
Example #26
0
 protected function _editState($state)
 {
     // check for request forgeries
     YRequest::checkToken() or jexit('Invalid Token');
     // init vars
     $cid = YRequest::getArray('cid', array(), 'int');
     if (count($cid) < 1) {
         JError::raiseError(500, JText::_('Select a comment to edit state'));
     }
     try {
         // get comment table
         $table = YTable::getInstance('comment');
         // update comment state
         foreach ($cid as $id) {
             $comment = $table->get($id);
             $comment->state = $state;
             $table->save($comment);
         }
     } catch (YException $e) {
         // raise notice on exception
         JError::raiseNotice(0, JText::_('Error editing Comment State') . ' (' . $e . ')');
     }
     $this->setRedirect($this->baseurl);
 }
Example #27
0
 function fetchElement($name, $value, &$node, $control_name)
 {
     JHTML::_('behavior.modal', 'a.modal');
     JHTML::stylesheet('zooapplication.css', ZOO_ADMIN_URI . '/joomla/elements/');
     JHTML::script('zooapplication.js', ZOO_ADMIN_URI . '/joomla/elements/');
     // init vars
     $params = $this->_parent;
     $table = YTable::getInstance('application');
     // set modes
     $modes = array();
     if ($node->attributes('categories')) {
         $modes[] = JHTML::_('select.option', 'categories', JText::_('Categories'));
     }
     if ($node->attributes('types')) {
         $modes[] = JHTML::_('select.option', 'types', JText::_('Types'));
     }
     if ($node->attributes('items')) {
         $modes[] = JHTML::_('select.option', 'item', JText::_('Item'));
     }
     // create application/category select
     $cats = array();
     $types = array();
     $options = array(JHTML::_('select.option', '', '- ' . JText::_('Select Application') . ' -'));
     foreach ($table->all(array('order' => 'name')) as $app) {
         // application option
         $options[] = JHTML::_('select.option', $app->id, $app->name);
         // create category select
         if ($node->attributes('categories')) {
             $attribs = 'class="category app-' . $app->id . ($value != $app->id ? ' hidden' : null) . '" role="' . $control_name . '[category]"';
             $opts = $node->attributes('frontpage') ? array(JHTML::_('select.option', '', '&#8226;	' . JText::_('Frontpage'))) : array();
             $cats[] = JHTML::_('zoo.categorylist', $app, $opts, $value == $app->id ? $control_name . '[category]' : null, $attribs, 'value', 'text', $params->get('category'));
         }
         // create types select
         if ($node->attributes('types')) {
             $opts = array();
             foreach ($app->getTypes() as $type) {
                 $opts[] = JHTML::_('select.option', $type->id, $type->name);
             }
             $attribs = 'class="type app-' . $app->id . ($value != $app->id ? ' hidden' : null) . '" role="' . $control_name . '[type]"';
             $types[] = JHTML::_('select.genericlist', $opts, $control_name . '[type]', $attribs, 'value', 'text', $params->get('type'));
         }
     }
     // create html
     $html[] = '<div id="' . $name . '" class="zoo-application">';
     $html[] = JHTML::_('select.genericlist', $options, $control_name . '[' . $name . ']', 'class="application"', 'value', 'text', $value);
     // create mode select
     if (count($modes) > 1) {
         $html[] = JHTML::_('select.genericlist', $modes, $control_name . '[mode]', 'class="mode"', 'value', 'text', $params->get('mode'));
     }
     // create categories html
     if (!empty($cats)) {
         $html[] = '<div class="categories">' . implode("\n", $cats) . '</div>';
     }
     // create types html
     if (!empty($types)) {
         $html[] = '<div class="types">' . implode("\n", $types) . '</div>';
     }
     // create items html
     $link = '';
     if ($node->attributes('items')) {
         $document = JFactory::getDocument();
         $field_name = $control_name . '[item_id]';
         $item_name = JText::_('Select Item');
         if ($item_id = $params->get('item_id')) {
             $item = YTable::getInstance('item')->get($item_id);
             $item_name = $item->name;
         }
         $link = 'index.php?option=com_zoo&controller=item&task=element&tmpl=component&func=selectZooItem&object=' . $name;
         $html[] = '<div class="item">';
         $html[] = '<input type="text" id="' . $name . '_name" value="' . htmlspecialchars($item_name, ENT_QUOTES, 'UTF-8') . '" disabled="disabled" />';
         $html[] = '<a class="modal" title="' . JText::_('Select Item') . '"  href="#" rel="{handler: \'iframe\', size: {x: 850, y: 500}}">' . JText::_('Select') . '</a>';
         $html[] = '<input type="hidden" id="' . $name . '_id" name="' . $field_name . '" value="' . (int) $item_id . '" />';
         $html[] = '</div>';
     }
     $html[] = '</div>';
     $javascript = 'jQuery("#' . $name . '").ZooApplication({ url: "' . JRoute::_($link, false) . '", msgSelectItem: "' . JText::_('Select Item') . '" });';
     $javascript = "<script type=\"text/javascript\">\n// <!--\n{$javascript}\n// -->\n</script>\n";
     return implode("\n", $html) . $javascript;
 }
Example #28
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);
     }
 }
Example #29
0
<?php

/**
* @package   ZOO Category
* @file      mod_zoocategory.php
* @version   2.1.0
* @author    YOOtheme http://www.yootheme.com
* @copyright Copyright (C) 2007 - 2011 YOOtheme GmbH
* @license   http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
// load config
require_once JPATH_ADMINISTRATOR . '/components/com_zoo/config.php';
// load helper
require_once dirname(__FILE__) . DS . 'helper.php';
$app = YTable::getInstance('application')->get($params->get('application', 0));
// is application ?
if (empty($app)) {
    return null;
}
// set one or multiple categories
$categories = array();
$all_categories = $app->getCategoryTree(true);
if (isset($all_categories[$params->get('category', 0)])) {
    $categories = $all_categories[$params->get('category', 0)]->getChildren();
}
if (count($categories)) {
    include JModuleHelper::getLayoutPath('mod_zoocategory', $params->get('theme', 'default'));
}
Example #30
0
 public function getCommentsCount($state = 1)
 {
     return YTable::getInstance('comment')->count(array('conditions' => array('state = ? AND item_id = ?', $state, $this->id)));
 }