Example #1
0
 /**
  * Renders the html markup for the user avatar
  *
  * @author Stian Didriksen <*****@*****.**>
  * @return string
  */
 public function image($config = array())
 {
     $params = KFactory::get('admin::com.ninjaboard.model.settings')->getParams();
     $prepend = KFactory::get('lib.joomla.application')->isAdmin() ? KRequest::root() . '/' : '';
     $config = new KConfig($config);
     $config->append(array('id' => KFactory::get('admin::com.ninjaboard.model.people')->getMe()->id, 'thumbnail' => 'large', 'class' => 'avatar', 'link' => 'person', 'type' => 'css'));
     $person = KFactory::tmp('admin::com.ninjaboard.model.people')->id($config->id)->getItem();
     $avatar_on = new DateTime($person->avatar_on);
     $cache = (int) $avatar_on->format('U');
     $config->append(array('avatarurl' => $prepend . JRoute::_('&option=com_ninjaboard&view=avatar&id=' . $config->id . '&thumbnail=' . $config->thumbnail . '&cache=' . $cache), 'profileurl' => $prepend . JRoute::_('&option=com_ninjaboard&view=person&id=' . $config->id)));
     $attribs = array('class' => $config->class, 'href' => $config->profileurl);
     $height = $params['avatar_settings'][$config->thumbnail . '_thumbnail_height'];
     $width = $params['avatar_settings'][$config->thumbnail . '_thumbnail_width'];
     ///* @TODO Following is the <img /> version, likely going to be deprecated
     if ($config->type == 'tag') {
         $attribs['src'] = $config->avatarurl;
         $attribs['height'] = $height;
         $attribs['width'] = $width;
         unset($attribs['href']);
         $html = '<img ' . KHelperArray::toString($attribs) . ' />';
     } else {
         $style = 'background-image: url(' . $config->avatarurl . '); ';
         $style .= 'height: ' . $height . 'px; ';
         $style .= 'width: ' . $width . 'px;';
         $attribs['style'] = $style;
         $html = '<a ' . KHelperArray::toString($attribs) . '></a>';
     }
     return $html;
 }
Example #2
0
 /**
  * @param KCommandContext $context
  */
 public function _actionCopy(KCommandContext $context)
 {
     foreach (KRequest::get('get.id', 'raw') as $item_id) {
         $this->count = 1;
         $items = array();
         $languages = JLanguageHelper::getLanguages();
         $model_identifier = clone $context->caller->getIdentifier();
         $model_identifier->path = array('model');
         $model_identifier->name = KInflector::pluralize($model_identifier->name);
         $isTranslatable = KService::get($model_identifier)->getTable()->hasBehavior('translatable');
         if ($isTranslatable) {
             foreach ($languages as $language) {
                 JFactory::getLanguage()->setLanguage($language->lang_code);
                 $item = $this->getService($model_identifier)->id($item_id)->getItem();
                 if ($item->original) {
                     $this->original_language = $language->lang_code;
                     $original = $item;
                 } else {
                     $items[$language->lang_code] = $item;
                 }
             }
         }
         JFactory::getLanguage()->setLanguage($this->original_language);
         $id = $this->_copyOriginal($original);
         if ($isTranslatable) {
             $this->_updateLanguages($id, $items);
         }
     }
 }
 public function _actionEdit(KCommandContext $context)
 {
     $data = $context->data;
     $model = $this->getModel();
     $table = $model->getTable();
     $query = KFactory::tmp('lib.koowa.database.query');
     $ids = array();
     foreach ($data['group'] as $joomla => $ninjaboard) {
         $ids[] = $joomla;
     }
     $table->getDatabase()->execute('TRUNCATE TABLE `#__ninjaboard_joomla_user_group_maps`');
     foreach ($ids as $id) {
         $table->getDatabase()->execute('INSERT INTO `#__ninjaboard_joomla_user_group_maps` (`joomla_gid`, `ninjaboard_gid`) VALUES (' . $id . ', ' . (int) $data['group'][$id] . ')');
         //$table->insert(array('joomla_gid' => $id, 'ninjaboard_gid' => $data['group'][$id]));
     }
     $tmpl = false;
     if (KRequest::get('post.tmpl', 'cmd') == 'component') {
         $tmpl = '&tmpl=component';
     }
     $this->_redirect = 'index.php?option=com_ninjaboard&view=joomlausergroupmaps' . $tmpl;
     if ($tmpl) {
         $this->_redirect_message = '<script type="text/javascript">window.parent.document.getElementById("sbox-btn-close").fireEvent("click")</script>';
     }
     // @TODO this is a temporary workaround, find out why the proper way, using setRedirect(), stopped working.
     echo $this->_redirect_message;
     //$this->setRedirect('view=joomlausergroupmaps'.$tmpl, $tmpl ? '<script type="text/javascript">window.parent.document.getElementById("sbox-btn-close").fireEvent("click")</script>' : null);
     return $this->getModel()->getList();
 }
Example #4
0
 /**
  * Method to upload and Add a photo.
  *
  * @param KCommandContext $context
  */
 protected function _actionAdd($context)
 {
     $data = $context->data;
     $file = KRequest::get('files.file', 'raw');
     $content = @file_get_contents($file['tmp_name']);
     $filesize = strlen($content);
     $uploadlimit = $this->_max_upload_limit * 1024 * 1024;
     $exif = function_exists('exif_read_data') ? @exif_read_data($file['tmp_name']) : array();
     if ($filesize == 0) {
         throw new LibBaseControllerExceptionBadRequest('File is missing');
         return;
     }
     if ($filesize > $uploadlimit) {
         throw new LibBaseControllerExceptionBadRequest('Exceed maximum size');
         return;
     }
     $orientation = 0;
     if (!empty($exif) && isset($exif['Orientation'])) {
         $orientation = $exif['Orientation'];
     }
     $data['portrait'] = array('data' => $content, 'rotation' => $orientation, 'mimetype' => isset($file['type']) ? $file['type'] : null);
     $photo = $this->actor->photos->addNew($data);
     $photo->setExifData($exif);
     $photo->save();
     $this->setItem($photo);
     $this->getResponse()->status = KHttpResponse::CREATED;
     if ($photo->body && preg_match('/\\S/', $photo->body)) {
         $context->append(array('story' => array('body' => $photo->body)));
     }
     return $photo;
 }
Example #5
0
 /**
  * Initializes the configuration for the object
  * 
  * Called from {@link __construct()} as a first step of object instantiation.
  *
  * @param   array   Configuration settings
  */
 protected function _initialize(KConfig $config)
 {
     $language = JFactory::getLanguage();
     $settings = array('directionality' => $language->isRTL() ? 'rtl' : 'ltr', 'editor_selector' => 'editable', 'mode' => 'specific_textareas', 'skin' => 'nooku', 'theme' => 'advanced', 'inline_styles' => true, 'gecko_spellcheck' => true, 'entity_encoding' => 'raw', 'extended_valid_elements' => '', 'invalid_elements' => 'script,applet,iframe', 'relative_urls' => true, 'remove_script_host' => false, 'document_base_url' => KRequest::root(), 'theme_advanced_toolbar_location' => 'top', 'theme_advanced_toolbar_align' => 'left', 'theme_advanced_source_editor_height' => '550', 'height' => '550', 'width' => '100%', 'theme_advanced_statusbar_location' => 'bottom', 'theme_advanced_resizing' => false, 'theme_advanced_resize_horizontal' => false, 'theme_advanced_path' => true, 'dialog_type' => 'modal', 'language' => substr($language->getTag(), 0, strpos($language->getTag(), '-')), 'theme_advanced_buttons1' => implode(',', array('bold', 'italic', 'strikethrough', 'underline', '|', 'bullist', 'numlist', 'blockquote', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', '|', 'link', 'unlink', '|', 'spellchecker', 'fullscreen', 'image', 'readmore', 'article', '|', 'advanced')), 'theme_advanced_buttons2' => implode(',', array('formatselect', 'forecolor', '|', 'pastetext', 'pasteword', 'removeformat', '|', 'media', 'charmap', '|', 'outdent', 'indent', '|', 'undo', 'redo')), 'theme_advanced_buttons3' => '', 'theme_advanced_buttons4' => '');
     $config->append(array('layout' => 'default', 'media_url' => KRequest::root() . '/media'))->append(array('codemirror' => true, 'codemirrorOptions' => array('stylesheet' => array($config->media_url . '/com_editors/codemirror/css/xmlcolors.css', $config->media_url . '/com_editors/codemirror/css/jscolors.css', $config->media_url . '/com_editors/codemirror/css/csscolors.css', $config->media_url . '/com_editors/css/codemirror.css'), 'path' => $config->media_url . '/com_editors/codemirror/js/'), 'editor_settings' => $settings));
     parent::_initialize($config);
 }
 public function __construct(KConfigInterface $config)
 {
     parent::__construct($config);
     if (KRequest::type() == 'AJAX' && KRequest::method() == 'POST') {
         $this->unregisterCallback('after.dispatch', array($this, 'forward'));
     }
 }
 protected function _actionApply(KCommandContext $context)
 {
     $data = $context->caller->execute('edit', $context);
     $url = clone KRequest::url();
     $this->setRedirect($url);
     return $data;
 }
Example #8
0
 /**
  * Upload the users avatar
  * 
  * @param	KCommandContext	A command context object
  * @return 	void
  */
 public function uploadAvatar(KCommandContext $context)
 {
     $avatar = KRequest::get('files.avatar', 'raw');
     if (!$avatar['name']) {
         return;
     }
     //Prepare MediaHelper
     JLoader::register('MediaHelper', JPATH_ROOT . '/components/com_media/helpers/media.php');
     // is it an image
     if (!MediaHelper::isImage($avatar['name'])) {
         JError::raiseWarning(21, sprintf(JText::_("%s failed to upload because it's not an image."), $avatar['name']));
         return;
     }
     // are we allowed to upload this filetype
     if (!MediaHelper::canUpload($avatar, $error)) {
         JError::raiseWarning(21, sprintf(JText::_("%s failed to upload because %s"), $avatar['name'], lcfirst($error)));
         return;
     }
     // @todo put in some max file size checks
     $path = 'images/com_portfolio/avatars/' . $context->data->user_id . '/';
     $ext = JFile::getExt($avatar['name']);
     $name = JFile::makeSafe($this->getService('koowa:filter.slug')->sanitize($context->data->title) . '.' . $ext);
     JFile::upload($avatar['tmp_name'], JPATH_ROOT . '/' . $path . $name);
     $context->data->avatar = $path . $name;
 }
Example #9
0
 /**
  * Logs in a user.
  *
  * @param array $user     The user as an array
  * @param bool  $remember Flag to whether remember the user or not
  *
  * @return bool
  */
 public function login(array $user, $remember = false)
 {
     $session =& JFactory::getSession();
     // we fork the session to prevent session fixation issues
     $session->fork();
     JFactory::getApplication()->_createSession($session->getId());
     // Import the user plugin group
     JPluginHelper::importPlugin('user');
     $options = array();
     $results = JFactory::getApplication()->triggerEvent('onLoginUser', array($user, $options));
     foreach ($results as $result) {
         if ($result instanceof JException || $result instanceof Exception || $result === false) {
             return false;
         }
     }
     //if remember is true, create a remember cookie that contains the ecrypted username and password
     if ($remember) {
         // Set the remember me cookie if enabled
         jimport('joomla.utilities.simplecrypt');
         jimport('joomla.utilities.utility');
         $key = JUtility::getHash(KRequest::get('server.HTTP_USER_AGENT', 'raw'));
         if ($key) {
             $crypt = new JSimpleCrypt($key);
             $cookie = $crypt->encrypt(serialize(array('username' => $user['username'], 'password' => $user['password'])));
             $lifetime = time() + 365 * 24 * 3600;
             setcookie(JUtility::getHash('JLOGIN_REMEMBER'), $cookie, $lifetime, '/');
         }
     }
     return true;
 }
Example #10
0
 public function display()
 {
     $this->assign('params', KFactory::get('admin::com.ninjaboard.model.settings')->getParams());
     $me = KFactory::get('admin::com.ninjaboard.model.people')->getMe();
     $this->showtopics = false;
     if (isset($this->params['view_settings']['displayed_elements']) && $me->topic_permissions > 0) {
         if (in_array('showtopics', $this->params['view_settings']['displayed_elements'])) {
             $this->showtopics = true;
             //$state		= KFactory::get($this->getModel())->getState();
             /*$this->limit	= KRequest::get('get.limit', 'int', 10);
             		$this->offset	= KRequest::get('get.offset', 'int', 0);
             		$topicsmodel	= KFactory::tmp('site::com.ninjaboard.model.topics')
             							->limit($this->limit)
             							->offset($this->offset)
             							->sort('last_post_date')
             							->direction('desc');
             		$this->total	= $topicsmodel->getTotal();
             		$this->length	= KFactory::tmp('site::com.ninjaboard.model.topics')->getTotal();
             		
             		$this->assign('pagination', 
             			KFactory::get('site::com.ninjaboard.template.helper.paginator', array('name' => 'topics'))
             				->pagination($this->total, $this->offset, $this->limit, 4)
             		);*/
             $this->limit = KRequest::get('get.limit', 'int', 10);
             $this->offset = KRequest::get('get.offset', 'int', 0);
             $this->total = KFactory::get('site::com.ninjaboard.model.topics')->getTotal();
             $this->assign('topics', KFactory::get('site::com.ninjaboard.controller.topic')->setView(KFactory::get('site::com.ninjaboard.view.topics.html'))->direction('desc')->sort('last_post_on')->limit($this->limit)->offset($this->offset)->layout('list')->display());
             $this->assign('pagination', KFactory::get('site::com.ninjaboard.template.helper.paginator', array('name' => 'topics'))->pagination($this->total, $this->offset, $this->limit, 4, false));
         }
     }
     return parent::display();
 }
Example #11
0
 public function beforeAdd(KCommandContext $context)
 {
     if (!$context->data->file) {
         $context->data->file = KRequest::get('files.file.tmp_name', 'raw');
         $context->data->path = KRequest::get('files.file.name', 'koowa:filter.filename');
     }
 }
Example #12
0
 /**
  * Generic function for setting the permissions
  *
  * @return void
  */
 public function setPermissions($context)
 {
     //Temp fix
     if (KInflector::isPlural(KRequest::get('get.view', 'cmd')) || KRequest::type() == 'AJAX') {
         return;
     }
     $model = KFactory::get($this->getModel());
     $table = KFactory::tmp(KFactory::get(KFactory::get('admin::com.ninja.helper.access')->models->assets)->getTable());
     $query = $table->getDatabase()->getQuery();
     $item = $model->getItem();
     $identifier = $this->getIdentifier();
     $id = $identifier->type . '_' . $identifier->package . '.' . $identifier->name . '.' . $item->id . '.';
     $permissions = (array) KRequest::get('post.permissions', 'int');
     $editable = KRequest::get('post.editpermissions', 'boolean', false);
     if (!$permissions && $editable) {
         $query->where('tbl.name', 'LIKE', $id . '%');
         $table->select($query)->delete();
     }
     $safe = array();
     $query = $table->getDatabase()->getQuery()->where('name', 'like', $id . '%');
     foreach ((array) KRequest::get('post.params.permissions', 'raw') as $group => $other) {
         $safe[] = $id . $group;
     }
     if ($safe) {
         $query->where('name', 'not in', $safe);
     }
     $table->select($query, KDatabase::FETCH_ROWSET)->delete();
     foreach ($permissions as $usergroup => $rules) {
         foreach ($rules as $name => $permission) {
             KFactory::tmp(KFactory::get('admin::com.ninja.helper.access')->models->assets)->name($id . $usergroup . '.' . $name)->getItem()->setData(array('name' => $id . $usergroup . '.' . $name, 'level' => $permission))->save();
         }
     }
 }
Example #13
0
 protected function _initialize(KConfig $config)
 {  
     //Force the view to prevent a redirect
     KRequest::set('get.view', 'results');
      
     parent::_initialize($config);
 }
Example #14
0
 public function render()
 {
     $name = $this->getName();
     $img = KTemplateAbstract::loadHelper('admin::com.ninja.helper.default.img', '/32/' . $name . '.png');
     if ($img) {
         KTemplateAbstract::loadHelper('admin::com.ninja.helper.default.css', '.toolbar .icon-32-' . $name . ' { background-image: url(' . $img . '); }');
     }
     $text = JText::_($this->_options['text']);
     $view = KRequest::get('get.view', 'cmd');
     $link = ' href="' . JRoute::_($this->getLink()) . '"';
     $html = array();
     // Sanitize the url since we can't trust the server var
     $url = KFactory::get('lib.koowa.filter.url')->sanitize($this->getLink());
     // Create the URI object
     $uri = KFactory::tmp('lib.koowa.http.uri', array('uri' => $url));
     $query = $uri->getQuery(1);
     $html[] = '<td class="button" id="' . $this->getId() . '">';
     $active = $view == KInflector::variablize(KInflector::pluralize($query['view'])) || $view == KInflector::variablize(KInflector::singularize($query['view']));
     $hide = !KInflector::isPlural($view);
     if ($active || $hide || !$this->modal) {
         $html[] = '<a class="toolbar inactive">';
     } else {
         $html[] = '<a' . $link . ' onclick="' . $this->getOnClick() . '" class="toolbar">';
     }
     $html[] = '<span class="' . $this->getClass() . '" title="' . $text . '">';
     $html[] = '</span>';
     $html[] = $text;
     if (!$active && !$hide || $this->modal) {
         $html[] = '</a>';
     } else {
         $html[] = '</a>';
     }
     $html[] = '</td>';
     return implode(PHP_EOL, $html);
 }
Example #15
0
 public function onBeforeDispatcherDispatch(KEvent $event)
 {
     $application = JFactory::getApplication();
     if ($application->getName() != 'site') {
         return;
     }
     //var_dump($_SERVER); exit();
     // check if SSO header is set
     $personnumber = KRequest::get('server.HTTP_P_SSO_IDENTIFIER', 'alnum');
     if (empty($personnumber) || !preg_match('/P\\d+/is', $personnumber)) {
         // TODO set proper http response
         throw new KException('Access not allowed');
     }
     // check if user is already logged in
     $user = JFactory::getUser();
     // make sure personnumber is still the same
     if (!$user->guest && $user->username != $personnumber) {
         $application->logout();
         $application->redirect(KRequest::url());
     }
     if ($user->guest) {
         $credentials = array('username' => $personnumber, 'password' => $personnumber);
         $result = $application->login($credentials, array());
         if (JError::isError($result)) {
             // TODO set proper http response
             throw new KException($result->getError());
         } else {
             $application->redirect('index.php');
         }
     }
 }
Example #16
0
 public function display()
 {
     $items = $this->getModel()->getList();
     $root = KRequest::url()->get(KHttpUri::PART_BASE ^ KHttpUri::PART_PATH);
     $xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>';
     $xml .= '<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:atom="http://www.w3.org/2005/Atom">';
     $xml .= '<channel>';
     $xml .= '<title>Posts RSS feed</title>';
     $xml .= '<description>RSS description</description>';
     $xml .= '<generator>' . JURI::base() . '</generator>';
     foreach ($items as $item) {
         $xml .= '<item>';
         $xml .= '<title>' . htmlspecialchars($item->title) . '</title>';
         $xml .= '<link>' . $root . JRoute::_('index.php?option=com_ninjaboard&view=topic&id=' . $item->ninjaboard_topic_id . '&post=' . $item->id . '#p' . $item->id) . '</link>';
         $xml .= '<description>' . htmlspecialchars(KFactory::get('admin::com.ninja.helper.bbcode')->parse(array('text' => $item->text))) . '</description>';
         $xml .= '<guid isPermaLink="false">' . $item->uuid . '</guid>';
         $xml .= '<media:title>' . htmlspecialchars($item->title) . '</media:title> ';
         $xml .= '<media:content url="' . $root . JRoute::_('index.php?option=com_ninjaboard&view=avatar&id=' . $item->created_by . '&format=file') . '"/>';
         $xml .= '</item>';
     }
     $xml .= '</channel>';
     $xml .= '</rss>';
     $this->output = $xml;
     return parent::display();
 }
Example #17
0
 public function getOnClick()
 {
     $id = KRequest::get('get.id', 'int');
     $token = JUtility::getToken();
     $json = "{method:'post', url:'index.php?option=com_create&view=component&id={$id}', formelem:'adminForm', params:{action:'generate', _token:'{$token}'}}";
     return 'new KForm(' . $json . ').submit();';
 }
Example #18
0
    public function display()
    {
        // Display the toolbar
        $toolbar = $this->_createToolbar()->reset();
        $this->toolbar = KFactory::get($this->getToolbar(), array('isGrid' => false))->append(KFactory::get('admin::com.ninja.toolbar.button.apply', array('isGrid' => false)));
        KFactory::get('admin::com.ninja.helper.default')->css('/' . $this->getIdentifier()->application . '.' . $this->getName() . '.css');
        KFactory::get('admin::com.ninja.helper.default')->js('/raphael.js');
        KFactory::get('admin::com.ninja.helper.default')->js('/Mapper.js');
        $acl = JFactory::getACL();
        //die('<pre>'.print_r(get_class_methods($acl), true).'</pre>');
        $acltree = (array) $acl->get_group_children_tree(null, 'USERS', false);
        array_unshift($acltree, (object) array('value' => 0, 'text' => 'Unregistered', 'disabled' => false));
        $this->acltree = $acltree;
        $this->usergroups = KFactory::tmp('admin::com.ninjaboard.model.usergroups')->limit(0)->getList();
        $maps = array();
        foreach (KFactory::tmp($this->getModel()->getIdentifier())->limit(0)->getList() as $map) {
            $maps[$map->id] = $map->ninjaboard_gid;
        }
        $this->maps = $maps;
        $display = parent::display();
        if (KRequest::type() == 'AJAX') {
            echo '<script type="text/javascript">
			' . $this->_document->_script['text/javascript'] . '
			</script>';
        }
        return $display;
    }
Example #19
0
 public function translations($config = array())
 {
     $config = new KConfig($config);
     $config->append(array('row' => null, 'table' => ''));
     // First for our knowledge we get the original language (if exists.)
     $original = $this->_getOriginalLanguage($config->row, $config->table);
     $html = '<style src="media://com_translations/css/translations.css" />';
     $view = KInflector::singularize(KRequest::get('get.view', 'string'));
     foreach ($this->_getLanguages() as $language) {
         $relation = $this->_getLanguage($config, $language->lang_code);
         if ($language->lang_code == $original->iso_code) {
             $html .= ' <a href="' . $this->getTemplate()->getView()->createRoute('view=' . $view . '&id=' . $config->row . '&backendlanguage=' . $language->lang_code) . '"><div class="badge badge-info">' . strtoupper(substr($language->lang_code, 0, 2)) . '</a></div>';
         } else {
             if ($relation->translated) {
                 $html .= ' <a href="' . $this->getTemplate()->getView()->createRoute('view=' . $view . '&id=' . $config->row . '&backendlanguage=' . $language->lang_code) . '"><div class="badge badge-success">' . strtoupper(substr($language->lang_code, 0, 2)) . '</a></div>';
             } else {
                 if (strtotime('+ 2 weeks', strtotime($original->created_on)) > strtotime(date('d-m-Y H:i:s'))) {
                     $html .= ' <a href="' . $this->getTemplate()->getView()->createRoute('view=' . $view . '&id=' . $config->row . '&backendlanguage=' . $language->lang_code) . '"><div class="badge badge-warning">' . strtoupper(substr($language->lang_code, 0, 2)) . '</a></div>';
                 } else {
                     if (strtotime('+ 2 weeks', strtotime($original->created_on)) < strtotime(date('d-m-Y H:i:s'))) {
                         $html .= ' <a href="' . $this->getTemplate()->getView()->createRoute('view=' . $view . '&id=' . $config->row . '&backendlanguage=' . $language->lang_code) . '"><div class="badge badge-important">' . strtoupper(substr($language->lang_code, 0, 2)) . '</a></div>';
                     }
                 }
             }
         }
     }
     return $html;
 }
Example #20
0
 public function display()
 {
     $targets = KFactory::tmp('site::com.stream.model.targets')->getList()->getData();
     $thing = reset($targets);
     $string = substr($thing['title'], 3);
     $option = strtolower(substr($string, 0, stripos($string, 'controller')));
     $view = strtolower(substr($string, stripos($string, 'controller') + 10));
     $model = KInflector::pluralize($view);
     $list = KFactory::tmp('site::com.' . $option . '.model.' . $model)->getList()->getData();
     $array = array();
     foreach ($list as $item) {
         $array[] = $item['id'];
     }
     //Get the list of posts
     $activities = KFactory::get($this->getModel())->set('parent_target_id', KRequest::get('get.parent_target_id', 'int'))->getList();
     $myactivities = array();
     foreach (@$activities as $activity) {
         if (!in_array($activity->parent_target_id, $array)) {
             continue;
         } else {
             $myactivities[] = $activity;
         }
     }
     $this->assign('myactivities', $myactivities);
     $this->assign('pagination', KFactory::get($this->getModel())->getState()->pagination);
     return parent::display();
 }
Example #21
0
 public function display()
 {
     //Set the document link
     $this->_document->link = $this->createRoute('format=html&view=posts&blog_blog_id=' . KRequest::get('get.id', 'int'));
     //Get the list of posts
     $posts = KFactory::get($this->getModel())->getList();
     foreach ($posts as $post) {
         // strip html from feed item title
         $title = html_entity_decode($post->title);
         // url link to article
         $link = $this->createRoute('format=html&view=post&slug=' . $post->slug);
         // generate the description as a hcard
         $description = $post->text;
         // load individual item creator class
         $item = new JFeedItem();
         $item->title = $title;
         $item->link = $link;
         $item->description = $description;
         $item->date = date('r', strtotime($post->created_on));
         $item->category = '';
         // loads item info into rss array
         $doc =& JFactory::getDocument();
         $doc->addItem($item);
     }
     return $this;
 }
Example #22
0
 public function __get($column)
 {
     if ($column == 'image_path') {
         return $this->image ? KRequest::root() . '/joomlatools-files/docman-images/' . $this->image : null;
     }
     if ($column == 'icon') {
         if (!is_object($this->params)) {
             $this->params = json_decode($this->params);
         }
         $icon = $this->params->icon ? $this->params->icon : 'icon:folder.png';
         return $icon;
     }
     if ($column == 'icon_path') {
         $icon = $this->icon;
         if (substr($icon, 0, 5) === 'icon:') {
             $icon = '/joomlatools-files/docman-icons/' . substr($icon, 5);
         } else {
             $icon = '/media/com_docman/images/icons/' . $icon;
         }
         return KRequest::root() . $icon;
     }
     if ($column === 'description_summary') {
         $description = $this->description;
         $position = strpos($description, '<hr id="system-readmore" />');
         if ($position !== false) {
             return substr($description, 0, $position);
         }
         return $description;
     }
     if ($column === 'description_full') {
         return str_replace('<hr id="system-readmore" />', '', $this->description);
     }
     return parent::__get($column);
 }
Example #23
0
 public function display()
 {
     $params = KFactory::get('admin::com.ninjaboard.model.settings')->getParams();
     $this->assign('params', $params);
     $person = KFactory::get($this->getModel())->getItem();
     if (KFactory::get('lib.joomla.user')->guest && (!$person->id || $this->getlayout() == 'form')) {
         $this->mixin(KFactory::get('admin::com.ninja.view.user.mixin'));
         $this->setLoginLayout();
         return parent::display();
     }
     if ($this->getLayout() != 'form') {
         $controller = KFactory::get('site::com.ninjaboard.controller.topic')->setView(KFactory::get('site::com.ninjaboard.view.topics.html'))->direction('desc')->sort('last_post_on')->limit(KRequest::get('get.limit', 'int', 10))->offset(KRequest::get('get.offset', 'int', 0))->at($this->getModel()->getItem()->id);
         $model = $controller->getModel();
         $state = $model->getState();
         $this->assign('topics', $this->render($controller->layout('list')->display(), JText::_('Latest Topics'), $params['module']));
         $this->assign('pagination', KFactory::get('site::com.ninjaboard.template.helper.paginator', array('name' => 'topics'))->pagination($model->getTotal(), $state->offset, $state->limit, 4, false));
         $me = KFactory::get($this->getModel())->getMe();
         $this->me = $me;
         if ($me->id === $person->id) {
             $this->edit_button = str_replace(array('$title', '$link'), array(JText::_('Edit Profile'), $this->createRoute('view=person&id=' . $person->id . '&layout=form')), $this->params['tmpl']['new_topic_button']);
         } else {
             $this->edit_button = false;
         }
         $this->message_button = $me->id && $this->params['messaging_settings']['enable_messaging'];
         $this->watch_button = $me->id && $this->params['email_notification_settings']['enable_email_notification'];
         $title = sprintf(JText::_("%s's profile"), $person->display_name);
     } else {
         $title = sprintf(JText::_("%s's settings"), $person->display_name);
         $this->save_button = str_replace('$title', JText::_('Save'), $this->params['tmpl']['create_topic_button']);
         $this->save_button = str_replace('$link', '#', $this->save_button);
     }
     $this->_subtitle = $title;
     $this->assign('title', $title);
     return parent::display();
 }
Example #24
0
 public function display()
 {
     $category = $this->getService('com://site/weblinks.model.categories')->getItem();
     $items = $this->getService('com://site/weblinks.model.weblinks')->catid(KRequest::get('get.id', 'int'))->getList();
     $xml = '<?xml version="1.0" encoding="utf-8"?>' . PHP_EOL;
     $xml .= '<rss version="2.0">' . PHP_EOL;
     $xml .= '<channel>' . PHP_EOL;
     $xml .= '	<title>' . $category->title . '</title>' . PHP_EOL;
     $xml .= '	<description><![CDATA[' . $category->description . ']]></description>' . PHP_EOL;
     $xml .= '	<link>' . KRequest::url() . '</link>' . PHP_EOL;
     $xml .= '	<lastBuildDate>' . date('r') . '</lastBuildDate>' . PHP_EOL;
     $xml .= '	<generator>' . JURI::base() . '</generator>' . PHP_EOL;
     $xml .= '	<language>' . JFactory::getLanguage()->getTag() . '</language>' . PHP_EOL;
     foreach ($items as $item) {
         $xml .= '	<item>' . PHP_EOL;
         $xml .= '		<title>' . htmlspecialchars($item->title) . '</title>' . PHP_EOL;
         $xml .= '		<link>' . JURI::base() . JRoute::_('index.php?option=com_weblinks&view=weblink&id=' . $item->id) . '</link>' . PHP_EOL;
         $xml .= '		<guid>' . JURI::base() . JRoute::_('index.php?option=com_weblinks&view=weblink&id=' . $item->id) . '</guid>' . PHP_EOL;
         $xml .= '		<description><![CDATA[' . htmlspecialchars($item->description) . ']]></description>' . PHP_EOL;
         $xml .= '		<category>' . $category->title . '</category>' . PHP_EOL;
         $xml .= '		<pubDate>' . date('r', strtotime($item->date)) . '</pubDate>' . PHP_EOL;
         $xml .= '	</item>' . PHP_EOL;
     }
     $xml .= '</channel>' . PHP_EOL;
     $xml .= '</rss>';
     $this->output = $xml;
     return parent::display();
 }
Example #25
0
 /**
  * Upload an icon for a work
  * 
  * @param   KCommandContext A command context object
  * @return  void
  */
 public function uploadIcon(KCommandContext $context)
 {
     $icon = KRequest::get('files.icon', 'raw');
     if (!$icon['name']) {
         return;
     }
     //Prepare MediaHelper
     JLoader::register('MediaHelper', JPATH_ROOT . '/components/com_media/helpers/media.php');
     // is it an image
     if (!MediaHelper::isImage($icon['name'])) {
         JError::raiseWarning(21, sprintf(JText::_("%s failed to upload because it's not an image."), $icon['name']));
         return;
     }
     // are we allowed to upload this filetype
     if (!MediaHelper::canUpload($icon, $error)) {
         JError::raiseWarning(21, sprintf(JText::_("%s failed to upload because %s"), $icon['name'], lcfirst($error)));
         return;
     }
     $slug = $this->getService('koowa:filter.slug');
     $path = 'images/com_portfolio/work/' . $slug->sanitize($context->data->title) . '/icon/';
     $ext = JFile::getExt($icon['name']);
     $name = JFile::makeSafe($slug->sanitize($context->data->title) . '.' . $ext);
     JFile::upload($icon['tmp_name'], JPATH_ROOT . '/' . $path . $name);
     $context->data->icon = $path . $name;
 }
Example #26
0
 /**
  * Render a sorting header
  * more language string suckyneess
  *
  * @param 	array 	An optional array with configuration options
  * @return	string	Html
  */
 public function sort($config = array())
 {
     $config = new KConfig($config);
     $config->append(array('title' => '', 'column' => '', 'direction' => 'asc', 'sort' => ''));
     //Set the title
     if (empty($config->title)) {
         $config->title = ucfirst($config->column);
     }
     //Set the direction
     $direction = strtolower($config->direction);
     $direction = in_array($direction, array('asc', 'desc')) ? $direction : 'asc';
     //Set the class
     $class = '';
     if ($config->column == $config->sort) {
         $direction = $direction == 'desc' ? 'asc' : 'desc';
         // toggle
         $class = 'class="-koowa-' . $direction . '"';
     }
     $url = clone KRequest::url();
     $query = $url->getQuery(1);
     $query['sort'] = $config->column;
     $query['direction'] = $direction;
     $url->setQuery($query);
     $html = '<a href="' . $url . '" title="' . JText::_('COM_PORTFOLIO_CLICK_TO_SORT') . '"  ' . $class . '>';
     $html .= JText::_($config->title);
     $html .= '</a>';
     return $html;
 }
Example #27
0
 /**
  * Helper for creating DOM element ids used by javascript behaviors
  *
  * If no type and package identifiers were supplied,
  * uses the current option $_GET variable, and changing com_foo_bar to com-foo_bar.
  * '-' are used as separators, and in our javascript used to parse identifier strings.
  * If a form got the id com-foo_bar-people, 
  * then we can assume that the toolbar will have the id toolbar-people,
  *
  * @author Stian Didriksen <*****@*****.**>
  * @param  array | int $parts
  * @return string
  */
 public function id($parts = array())
 {
     if (!is_array($parts) && is_int($parts)) {
         $parts['id'] = (int) $parts;
     }
     // If we pass a string, set $parts back as an array in order to proceed.
     if (!is_array($parts)) {
         settype($parts, 'array');
     }
     // Set the defaults, if needed
     $defaults = array();
     if (!isset($parts['type.package'])) {
         // We only want to replace the first underscore, not the rest.
         $defaults['type_package'] = str_replace('com_', 'com-', KRequest::get('get.option', 'cmd'));
     }
     if (!isset($parts['view'])) {
         $view = KRequest::get('get.view', 'cmd');
         // The view part always needs to be plural to allow ajax BREAD.
         if (KInflector::isSingular($view)) {
             $view = KInflector::pluralize($view);
         }
         $defaults['view'] = $view;
     }
     if (!isset($parts['id']) && KRequest::has('get.id', 'int')) {
         $defaults['id'] = KRequest::get('get.id', 'int');
     }
     // Filter away parts that are unset on purpose using a null value, or a negative boolean.
     return implode('-', array_filter(array_merge($defaults, $parts)));
 }
Example #28
0
 public function __construct($subject, $config = array())
 {
     // Turn off E_STRICT errors for now
     error_reporting(error_reporting() & ~E_STRICT);
     // Check if database type is MySQLi
     if (JFactory::getApplication()->getCfg('dbtype') != 'mysqli') {
         if (JFactory::getApplication()->getName() === 'administrator') {
             $string = version_compare(JVERSION, '1.6', '<') ? 'mysqli' : 'MySQLi';
             $link = JRoute::_('index.php?option=com_config');
             $error = 'In order to use Joomlatools framework, your database type in Global Configuration should be set to <strong>%1$s</strong>. Please go to <a href="%2$s">Global Configuration</a> and in the \'Server\' tab change your Database Type to <strong>%1$s</strong>.';
             JError::raiseWarning(0, sprintf(JText::_($error), $string, $link));
         }
         return;
     }
     // Set pcre.backtrack_limit to a larger value
     // See: https://bugs.php.net/bug.php?id=40846
     if (version_compare(PHP_VERSION, '5.3.6', '<=') && @ini_get('pcre.backtrack_limit') < 1000000) {
         @ini_set('pcre.backtrack_limit', 1000000);
     }
     //Set constants
     define('KDEBUG', JDEBUG);
     //Set path definitions
     define('JPATH_FILES', JPATH_ROOT);
     define('JPATH_IMAGES', JPATH_ROOT . DIRECTORY_SEPARATOR . 'images');
     //Set exception handler
     set_exception_handler(array($this, 'exceptionHandler'));
     // Koowa : setup
     require_once JPATH_LIBRARIES . '/koowa/koowa.php';
     Koowa::getInstance(array('cache_prefix' => md5(JFactory::getApplication()->getCfg('secret')) . '-cache-koowa', 'cache_enabled' => false));
     KLoader::addAdapter(new KLoaderAdapterModule(array('basepath' => JPATH_BASE)));
     KLoader::addAdapter(new KLoaderAdapterPlugin(array('basepath' => JPATH_ROOT)));
     KLoader::addAdapter(new KLoaderAdapterComponent(array('basepath' => JPATH_BASE)));
     KServiceIdentifier::addLocator(KService::get('koowa:service.locator.module'));
     KServiceIdentifier::addLocator(KService::get('koowa:service.locator.plugin'));
     KServiceIdentifier::addLocator(KService::get('koowa:service.locator.component'));
     KServiceIdentifier::setApplication('site', JPATH_SITE);
     KServiceIdentifier::setApplication('admin', JPATH_ADMINISTRATOR);
     KService::setAlias('koowa:database.adapter.mysqli', 'com://admin/default.database.adapter.mysqli');
     KService::setAlias('translator', 'com:default.translator');
     //Setup the request
     if (JFactory::getApplication()->getName() !== 'site') {
         KRequest::root(str_replace('/' . JFactory::getApplication()->getName(), '', KRequest::base()));
     }
     //Load the koowa plugins
     JPluginHelper::importPlugin('koowa', null, true);
     //Bugfix : Set offset accoording to user's timezone
     if (!JFactory::getUser()->guest) {
         if ($offset = JFactory::getUser()->getParam('timezone')) {
             if (version_compare(JVERSION, '3.0', '>=')) {
                 JFactory::getConfig()->set('offset', $offset);
             } else {
                 JFactory::getConfig()->setValue('config.offset', $offset);
             }
         }
     }
     // Load language files for the framework
     KService::get('com:default.translator')->loadLanguageFiles();
     parent::__construct($subject, $config);
 }
Example #29
0
 public function display()
 {
     $topic = $this->getModel()->getItem();
     $this->forum = KFactory::get('site::com.ninjaboard.model.forums')->id($topic->forum_id)->getItem();
     $this->user = KFactory::get('lib.joomla.user');
     $me = KFactory::get('admin::com.ninjaboard.model.people')->getMe();
     $this->watch_button = $me->id && $this->forum->params['email_notification_settings']['enable_email_notification'];
     //Assign forum permissions to topic
     $topic->forum_permissions = $this->forum->forum_permissions;
     $topic->topic_permissions = $this->forum->topic_permissions;
     $topic->post_permissions = $this->forum->post_permissions;
     $topic->attachment_permissions = $this->forum->attachment_permissions;
     if ((!$this->forum->id || !$topic->id || $topic->topic_permissions < 1) && KFactory::tmp('lib.joomla.user')->guest) {
         $this->mixin(KFactory::get('admin::com.ninja.view.user.mixin'));
         $this->setLoginLayout();
         return parent::display();
     } elseif (!$topic->id) {
         JError::raiseError(404, JText::_("Topic not found."));
         return;
     } elseif (!$this->forum->id) {
         JError::raiseError(404, JText::_("Forum not found."));
         return;
     }
     $this->_subtitle = $topic->title;
     //if($topic->id && !KRequest::get('get.layout', 'cmd', false)) $this->setLayout('default');
     $state = $this->getModel()->getState();
     $limit = $state->limit ? $state->limit : 6;
     $offset = KFactory::tmp('site::com.ninjaboard.model.posts')->topic($topic->id)->post($state->post)->limit($limit)->getOffset();
     $offset = KRequest::get('get.offset', 'int', $offset);
     //This is used to set the canonical link correctly in the topic controller after.read
     //@TODO move all this logic out of the view in 1.2
     $this->getModel()->set(array('limit' => $limit, 'offset' => $offset));
     $this->assign('posts', KFactory::tmp('site::com.ninjaboard.controller.post')->setView(KFactory::tmp('site::com.ninjaboard.view.posts.html'))->setModel(KFactory::get('site::com.ninjaboard.model.posts')->setAcl(false))->sort('created_on')->limit($limit)->offset($offset)->post(false)->topic($topic->id)->layout('default')->display());
     if ($this->forum->params['view_settings']['new_topic_button'] == 'topic') {
         $this->new_topic_button = '<div class="new-topic">' . str_replace(array('$title', '$link'), array(JText::_('New Topic'), $this->createRoute('view=post&forum=' . $this->forum->id)), $this->forum->params['tmpl']['new_topic_button']) . '</div>';
     }
     $button = false;
     if (KFactory::get('lib.joomla.user')->guest || $this->forum->post_permissions > 1) {
         $button = str_replace(array('$title', '$link'), array(JText::_('Reply topic'), $this->createRoute('view=post&topic=' . $topic->id)), $this->forum->params['tmpl']['new_topic_button']);
     }
     //$this->reply_topic_button = $this->forum->post_permissions > 1 ? $button : null;
     $this->reply_topic_button = $button;
     $this->lock_topic_button = null;
     $this->move_topic_button = null;
     $this->delete_topic_button = null;
     if ($this->forum->topic_permissions > 2) {
         $this->lock_topic_button = $this->_createActionButton('lock', 'Lock topic', $topic->id, 'lock');
         $this->move_topic_button = str_replace(array('$title', '$link'), array(JText::_('Move topic'), $this->createRoute('view=topic&layout=move&id=' . $topic->id)), $this->forum->params['tmpl']['new_topic_button']);
         $this->delete_topic_button = $this->_createActionButton('delete', 'Delete topic', $topic->id, 'trash');
     }
     $output = parent::display();
     //@TODO move this to the controller
     $hit = KRequest::get('session.' . KFactory::get('admin::com.ninja.helper.default')->formid($topic->id), 'boolean');
     if (!$hit && $topic->created_user_id != $me->id) {
         $topic->hit();
         KRequest::set('session.' . KFactory::get('admin::com.ninja.helper.default')->formid($topic->id), true);
     }
     return $output;
 }
Example #30
0
 /**
  * Restores a state for an action
  * 
  * @param  string $action
  * @return void
  */
 public function persistState($action)
 {
     $state = $this->getRequest();
     // Built the session identifier based on the action
     $identifier = $this->_mixer->getIdentifier() . '.' . $action;
     //Set the state in the session
     KRequest::set('session.' . $identifier, KConfig::unbox($state));
 }