Beispiel #1
0
 /**
  * Look for a term and prints it
  *
  * @access  public
  * @return  string  XHTML template content
  */
 function ViewTerm()
 {
     $term = jaws()->request->fetch('term', 'get');
     $term = Jaws_XSS::defilter($term);
     $model = $this->gadget->model->load('Term');
     $term = $model->GetTerm($term);
     if (!Jaws_Error::IsError($term) && isset($term['term'])) {
         $this->SetTitle($term['term']);
         $tpl = $this->gadget->template->load('ViewTerm.html');
         $tpl->SetBlock('definition');
         $tpl->SetVariable('title', $this->gadget->title);
         $date = Jaws_Date::getInstance();
         $tpl->SetBlock('definition/term');
         $tpl->SetVariable('term', $term['term']);
         $tid = empty($term['fast_url']) ? $term['id'] : $term['fast_url'];
         $tpl->SetVariable('url', $this->gadget->urlMap('ViewTerm', array('term' => $tid)));
         $tpl->SetVariable('description', $this->gadget->ParseText($term['description']));
         $tpl->SetVariable('created_in', _t('GLOBAL_CREATETIME'));
         $tpl->SetVariable('updated_in', _t('GLOBAL_UPDATETIME'));
         $tpl->SetVariable('createtime', $date->Format($term['createtime']));
         $tpl->SetVariable('updatetime', $date->Format($term['updatetime']));
         $tpl->ParseBlock('definition/term');
         $tpl->ParseBlock('definition');
     } else {
         return Jaws_HTTPError::Get(404);
     }
     return $tpl->Get();
 }
Beispiel #2
0
 /**
  * Displays an Atom feed for a given blog category
  *
  * @access  public
  * @return  string  xml with Atom feed
  */
 function ShowAtomCategory()
 {
     header('Content-type: application/atom+xml; charset=utf-8');
     $id = jaws()->request->fetch('id', 'get');
     $id = Jaws_XSS::defilter($id);
     $model = $this->gadget->model->load('Feeds');
     $xml = $model->MakeCategoryAtom($id);
     if (Jaws_Error::IsError($xml)) {
         return '';
     }
     return $xml;
 }
Beispiel #3
0
 /**
  * Displays a block of pages belongs to the specified group
  *
  * @access  public
  * @param   mixed   $gid    ID or fast_url of the group (int/string)
  * @param   int     $orderBy
  * @param   int     $limit    limit show pages
  * @return  string  XHTML content
  */
 function GroupPages($gid = 0, $orderBy = 1, $limit = 0)
 {
     if (empty($gid)) {
         $get = $this->gadget->request->fetch(array('gid', 'order'), 'get');
         $gid = Jaws_XSS::defilter($get['gid']);
         $orderBy = $get['order'];
     }
     $pModel = $this->gadget->model->load('Page');
     $gModel = $this->gadget->model->load('Group');
     $group = $gModel->GetGroup($gid);
     if (Jaws_Error::IsError($group) || $group == null) {
         return false;
     }
     if (!$this->gadget->GetPermission('AccessGroup', $group['id'])) {
         return Jaws_HTTPError::Get(403);
     }
     $GLOBALS['app']->Layout->SetTitle($group['title']);
     $GLOBALS['app']->Layout->AddToMetaKeywords($group['meta_keywords']);
     $GLOBALS['app']->Layout->SetDescription($group['meta_description']);
     if (!is_numeric($gid)) {
         $gid = $group['id'];
     }
     $pages = $pModel->GetPages($gid, $limit, $orderBy, null, true);
     if (Jaws_Error::IsError($pages)) {
         return false;
     }
     $tpl = $this->gadget->template->load('StaticPage.html');
     $tpl->SetBlock('group_pages');
     $tpl->SetVariable('title', $group['title']);
     foreach ($pages as $page) {
         $param = array('gid' => empty($group['fast_url']) ? $group['id'] : $group['fast_url'], 'pid' => empty($page['fast_url']) ? $page['base_id'] : $page['fast_url']);
         $link = $this->gadget->urlMap('Pages', $param);
         $tpl->SetBlock('group_pages/item');
         $tpl->SetVariable('page', $page['title']);
         $tpl->SetVariable('link', $link);
         $tpl->ParseBlock('group_pages/item');
     }
     // parsing read-more block if required
     if (!empty($limit) && count($pages) >= $limit && $GLOBALS['app']->requestedActionMode == ACTION_MODE_LAYOUT) {
         $urlParam = array('gid' => empty($group['fast_url']) ? $group['id'] : $group['fast_url'], 'order' => $orderBy);
         // prevent duplicate content via two different url
         if ($orderBy == 1) {
             unset($urlParam['order']);
         }
         $tpl->SetBlock('group_pages/read-more');
         $tpl->SetVariable('url', $this->gadget->urlMap('GroupPages', $urlParam));
         $tpl->SetVariable('read_more', _t('STATICPAGE_GROUP_PAGES_LIST', $group['title']));
         $tpl->ParseBlock('group_pages/read-more');
     }
     $tpl->ParseBlock('group_pages');
     return $tpl->Get();
 }
Beispiel #4
0
 /**
  * Updates the emblem
  *
  * @access  public
  * @return  array   Response array (notice or error)
  */
 function UpdateEmblem()
 {
     @(list($id, $data) = jaws()->request->fetch(array('0', '1:array'), 'post'));
     $data['url'] = Jaws_XSS::defilter($data['url']);
     $model = $this->gadget->model->loadAdmin('Emblems');
     $res = $model->UpdateEmblem($id, $data);
     if (Jaws_Error::IsError($res)) {
         $GLOBALS['app']->Session->PushLastResponse(_t('GLOBAL_ERROR_QUERY_FAILED'), RESPONSE_ERROR);
         return new Jaws_Error($res->getMessage());
     }
     $GLOBALS['app']->Session->PushLastResponse(_t('EMBLEMS_UPDATED'), RESPONSE_NOTICE);
     return $GLOBALS['app']->Session->PopLastResponse();
 }
Beispiel #5
0
 /**
  * Show links of the category
  *
  * @access  public
  * @return  mixed  XHTML template content or false on error
  */
 function Category($gid = 0)
 {
     if (empty($gid)) {
         $gid = $this->gadget->request->fetch('id', 'get');
         $gid = Jaws_XSS::defilter($gid);
         $limit_count = null;
         $tplFile = 'Category.html';
     } else {
         $limit_count = 10;
         $tplFile = 'LinkDump.html';
     }
     $model = $this->gadget->model->load('Groups');
     $group = $model->GetGroup($gid);
     if (Jaws_Error::IsError($group) || empty($group)) {
         return false;
     }
     $tpl = $this->gadget->template->load($tplFile);
     $tpl->SetBlock('category');
     $tpl->SetVariable('gid', $group['id']);
     $tpl->SetVariable('title', $this->gadget->title);
     $tpl->SetVariable('name', $group['title']);
     $tpl->SetVariable('feed', _t('LINKDUMP_LINKS_FEED'));
     $gid = empty($group['fast_url']) ? $group['id'] : $group['fast_url'];
     $tpl->SetVariable('url_category', $this->gadget->urlMap('Category', array('id' => $gid)));
     $group_id = empty($group['fast_url']) ? $group['id'] : $group['fast_url'];
     $tpl->SetVariable('linkdump_rss', $this->gadget->urlMap('RSS', array('id' => $group_id)));
     $target = $this->gadget->registry->fetch('links_target');
     $target = $target == 'blank' ? '_blank' : '_self';
     $block = $group['link_type'] == 0 ? 'list' : 'link';
     $links = $model->GetGroupLinks($group['id'], empty($limit_count) ? null : $group['limit_count'], $group['order_type']);
     if (!Jaws_Error::IsError($links)) {
         foreach ($links as $link) {
             $tpl->SetBlock("category/{$block}");
             $tpl->SetVariable('target', $target);
             $tpl->SetVariable('title', $link['title']);
             $tpl->SetVariable('description', $link['description']);
             $tpl->SetVariable('url', $link['url']);
             $tpl->SetVariable('clicks', $link['clicks']);
             $tpl->SetVariable('lbl_clicks', _t('LINKDUMP_LINKS_CLICKS'));
             if ($group['link_type'] == 2) {
                 $lid = empty($link['fast_url']) ? $link['id'] : $link['fast_url'];
                 $tpl->SetVariable('visit_url', $this->gadget->urlMap('Link', array('id' => $lid)));
             } else {
                 $tpl->SetVariable('visit_url', $link['url']);
             }
             $tpl->ParseBlock("category/{$block}");
         }
     }
     $tpl->ParseBlock('category');
     return $tpl->Get();
 }
Beispiel #6
0
 /**
  * Builds the advanced search box
  *
  * @access  public
  * @return  string  XHTML search box
  */
 function AdvancedBox()
 {
     $post = jaws()->request->fetch(array('all', 'exact', 'least', 'exclude', 'gadgets', 'date'), 'get');
     $post['all'] = Jaws_XSS::defilter($post['all']);
     $tpl = $this->gadget->template->load('Search.html');
     $tpl->SetBlock('AdvancedBox');
     $tpl->SetVariable('base_script', BASE_SCRIPT);
     $tpl->SetVariable('title', $this->gadget->title);
     $tpl->SetVariable('lbl_word_filter', _t('SEARCH_WORD_FILTER'));
     $tpl->SetVariable('lbl_all', _t('SEARCH_WORD_FILTER_ALL'));
     $tpl->SetVariable('lbl_exact', _t('SEARCH_WORD_FILTER_EXACT'));
     $tpl->SetVariable('lbl_least', _t('SEARCH_WORD_FILTER_LEAST'));
     $tpl->SetVariable('lbl_exclude', _t('SEARCH_WORD_FILTER_EXCLUDE'));
     $tpl->SetVariable('lbl_data_filter', _t('SEARCH_DATA_FILTER'));
     $tpl->SetVariable('lbl_search_in', _t('SEARCH_SEARCH_IN'));
     $model = $this->gadget->model->load('Search');
     $options = $model->parseSearch($post, $searchable);
     $wordAll =& Piwi::CreateWidget('Entry', 'all', implode(' ', $options['all']));
     $wordExact =& Piwi::CreateWidget('Entry', 'exact', implode(' ', $options['exact']));
     $wordLeast =& Piwi::CreateWidget('Entry', 'least', implode(' ', $options['least']));
     $wordExclude =& Piwi::CreateWidget('Entry', 'exclude', implode(' ', $options['exclude']));
     $tpl->SetVariable('all', $wordAll->Get());
     $tpl->SetVariable('exclude', $wordExclude->Get());
     $tpl->SetVariable('least', $wordLeast->Get());
     $tpl->SetVariable('exact', $wordExact->Get());
     //Gadgets filter combo
     $gadgetList = $model->GetSearchableGadgets();
     $gSearchable = $this->gadget->registry->fetch('searchable_gadgets');
     $searchableGadgets = $gSearchable == '*' ? array_keys($gadgetList) : explode(', ', $gSearchable);
     $gchk =& Piwi::CreateWidget('Combo', 'gadgets');
     $gchk->addOption(_t('GLOBAL_ALL'), '');
     foreach ($searchableGadgets as $gadget) {
         $info = Jaws_Gadget::getInstance($gadget);
         if (Jaws_Error::IsError($info)) {
             continue;
         }
         $gchk->AddOption($info->title, $gadget);
     }
     $default = !is_null($post['gadgets']) ? $post['gadgets'] : '';
     $gchk->SetDefault($default);
     $tpl->SetVariable('gadgets_combo', $gchk->Get());
     //Search button
     $btnSearch =& Piwi::CreateWidget('Button', '', _t('SEARCH_BUTTON'));
     $btnSearch->SetID('btn_search');
     $btnSearch->SetSubmit(true);
     $tpl->SetVariable('btn_search', $btnSearch->Get());
     $tpl->ParseBlock('AdvancedBox');
     return $tpl->Get();
 }
Beispiel #7
0
 /**
  * Displays a concrete category
  *
  * @access  public
  * @return  string  XHTML template content
  */
 function ViewCategory()
 {
     $model = $this->gadget->model->load('Question');
     $cat_id = jaws()->request->fetch('id', 'get');
     $cat_id = Jaws_XSS::defilter($cat_id);
     $this->SetTitle($this->gadget->title . ' - ' . _t('FAQ_CATEGORIES'));
     $questions = $model->GetQuestions($cat_id, true);
     if (is_array($questions) && count($questions) > 0) {
         $tpl = $this->gadget->template->load('Category.html');
         foreach ($questions as $cat) {
             $tpl->SetBlock('faq_category');
             $tpl->SetVariable('title', _t('FAQ_TITLE'));
             $tpl->SetVariable('category', $cat['category']);
             $tpl->SetVariable('description', $this->gadget->ParseText($cat['description']));
             if (isset($cat['questions']) && is_array($cat['questions'])) {
                 $qPos = 0;
             }
             foreach ($cat['questions'] as $q) {
                 $qPos++;
                 $tpl->SetBlock('faq_category/question');
                 $tpl->SetVariable('id', $q['id']);
                 $tpl->SetVariable('pos', $qPos);
                 $tpl->SetVariable('question', $q['question'], 'Faq', false);
                 $tpl->SetVariable('url', $this->gadget->urlMap('ViewCategory', array('id' => $cat_id)));
                 $tpl->ParseBlock('faq_category/question');
             }
             if (isset($cat['questions']) && is_array($cat['questions'])) {
                 $qPos = 0;
             }
             foreach ($cat['questions'] as $q) {
                 $qPos++;
                 $tpl->SetBlock('faq_category/item');
                 $tpl->SetVariable('top_label', _t('FAQ_GO_TO_TOP'));
                 $tpl->SetVariable('top_link', $this->gadget->urlMap('ViewCategory', array('id' => $cat_id)) . '#topfaq');
                 $tpl->SetVariable('id', $q['id']);
                 $tpl->SetVariable('pos', $qPos);
                 $qid = empty($q['fast_url']) ? $q['id'] : $q['fast_url'];
                 $tpl->SetVariable('url', $this->gadget->urlMap('ViewQuestion', array('id' => $qid)));
                 $tpl->SetVariable('question', $q['question']);
                 $tpl->SetVariable('answer', $this->gadget->ParseText($q['answer']));
                 $tpl->ParseBlock('faq_category/item');
             }
             $tpl->ParseBlock('faq_category');
         }
         return $tpl->Get();
     }
     // FIXME: We should return something like "No questions found"
     return '';
 }
Beispiel #8
0
 /**
  * Redirect to the URL and increase the clicks by one
  * 
  * @access  public
  */
 function Link()
 {
     $lid = jaws()->request->fetch('id', 'get');
     $lid = Jaws_XSS::defilter($lid);
     $model = $this->gadget->model->load('Links');
     $link = $model->GetLink($lid);
     if (!Jaws_Error::IsError($link) && !empty($link)) {
         $click = $model->Click($link['id']);
         if (!Jaws_Error::IsError($click)) {
             Jaws_Header::Location($link['url'], null, 301);
         }
     }
     // By default, on the errors stay in the main page
     Jaws_Header::Referrer();
 }
Beispiel #9
0
 /**
  * Displays a concrete question & answer
  *
  * @access  public
  * @return  string  XHTML template content
  */
 function ViewQuestion()
 {
     $qid = jaws()->request->fetch('id', 'get');
     $qid = Jaws_XSS::defilter($qid);
     $tpl = $this->gadget->template->load('Question.html');
     $tpl->SetBlock('faq_question');
     $model = $this->gadget->model->load('Question');
     $q = $model->GetQuestion($qid);
     if (!Jaws_Error::IsError($q) && !empty($q)) {
         $this->SetTitle($q['question']);
         $tpl->SetVariable('title', $q['question']);
         $tpl->SetVariable('answer', $this->gadget->ParseText($q['answer']));
     }
     $tpl->ParseBlock('faq_question');
     return $tpl->Get();
 }
Beispiel #10
0
 /**
  * Displays a list of blog posts included on the given category
  *
  * @access  public
  * @param   int     $cat    category ID
  * @return  string  XHTML template content
  */
 function ShowCategory($cat = null)
 {
     $cModel = $this->gadget->model->load('Categories');
     $pModel = $this->gadget->model->load('Posts');
     $rqst = jaws()->request->fetch(array('id', 'page'), 'get');
     $page = $rqst['page'];
     if (is_null($page) || $page <= 0) {
         $page = 1;
     }
     if (is_null($cat)) {
         if (empty($rqst['id'])) {
             $catInfo = array('id' => 0, 'name' => _t('BLOG_UNCATEGORIZED'), 'fast_url' => '', 'description' => '', 'meta_keywords' => '', 'meta_description' => '');
         } else {
             $cat = Jaws_XSS::defilter($rqst['id']);
             $catInfo = $cModel->GetCategory($cat);
             if (Jaws_Error::IsError($catInfo) || empty($catInfo)) {
                 return Jaws_HTTPError::Get(404);
             }
             // Check dynamic ACL
             if (!$this->gadget->GetPermission('CategoryAccess', $catInfo['id'])) {
                 return Jaws_HTTPError::Get(403);
             }
         }
     }
     $name = $catInfo['name'];
     $tpl = $this->gadget->template->load('CategoryPosts.html');
     $GLOBALS['app']->Layout->AddHeadLink($this->gadget->urlMap('ShowAtomCategory', array('id' => $cat)), 'alternate', 'application/atom+xml', 'Atom - ' . $name);
     $GLOBALS['app']->Layout->AddHeadLink($this->gadget->urlMap('ShowRSSCategory', array('id' => $cat)), 'alternate', 'application/rss+xml', 'RSS 2.0 - ' . $name);
     $this->SetTitle($name);
     $this->AddToMetaKeywords($catInfo['meta_keywords']);
     $this->SetDescription($catInfo['meta_description']);
     $tpl->SetBlock('view_category');
     $tpl->SetVariable('title', $name);
     $total = $cModel->GetCategoryNumberOfPages($catInfo['id']);
     $limit = $this->gadget->registry->fetch('last_entries_limit');
     $params = array('id' => $cat);
     $tpl->SetVariable('navigation', $this->GetNumberedPageNavigation($page, $limit, $total, 'ShowCategory', $params));
     $entries = $pModel->GetEntriesByCategory($catInfo['id'], $page);
     if (!Jaws_Error::IsError($entries)) {
         foreach ($entries as $entry) {
             $this->ShowEntry($tpl, 'view_category', $entry);
         }
     }
     $tpl->ParseBlock('view_category');
     return $tpl->Get();
 }
Beispiel #11
0
 /**
  * Creates a new note
  *
  * @access  public
  * @return  array   Response array
  */
 function CreateNote()
 {
     $data = jaws()->request->fetch(array('title', 'content'), 'post');
     if (empty($data['title']) || empty($data['content'])) {
         $GLOBALS['app']->Session->PushResponse(_t('NOTEPAD_ERROR_INCOMPLETE_DATA'), 'Notepad.Response', RESPONSE_ERROR, $data);
         Jaws_Header::Referrer();
     }
     $model = $this->gadget->model->load('Notepad');
     $data['user'] = (int) $GLOBALS['app']->Session->GetAttribute('user');
     $data['title'] = Jaws_XSS::defilter($data['title']);
     $data['content'] = Jaws_XSS::defilter($data['content']);
     $result = $model->Insert($data);
     if (Jaws_Error::IsError($result)) {
         $GLOBALS['app']->Session->PushResponse(_t('NOTEPAD_ERROR_NOTE_CREATE'), 'Notepad.Response', RESPONSE_ERROR, $data);
         Jaws_Header::Referrer();
     }
     $GLOBALS['app']->Session->PushResponse(_t('NOTEPAD_NOTICE_NOTE_CREATED'), 'Notepad.Response');
     Jaws_Header::Location($this->gadget->urlMap('Notepad'));
 }
Beispiel #12
0
 /**
  * Displays a block of pages belongs to the specified group
  *
  * @access  public
  * @param   mixed   $gid    ID or fast_url of the group (int/string)
  * @param   int     $orderBy
  * @param   int     $limit    limit show pages
  * @return  string  XHTML content
  */
 function GroupPages($gid = 0, $orderBy = 1, $limit = 0)
 {
     if (empty($gid)) {
         $get = $this->gadget->request->fetch(array('gid', 'order'), 'get');
         $gid = Jaws_XSS::defilter($get['gid']);
         $orderBy = $get['order'];
     }
     $pModel = $this->gadget->model->load('Page');
     $gModel = $this->gadget->model->load('Group');
     $group = $gModel->GetGroup($gid);
     if (Jaws_Error::IsError($group) || $group == null) {
         return false;
     }
     if (!$this->gadget->GetPermission('AccessGroup', $group['id'])) {
         return Jaws_HTTPError::Get(403);
     }
     $GLOBALS['app']->Layout->SetTitle($group['title']);
     $GLOBALS['app']->Layout->AddToMetaKeywords($group['meta_keywords']);
     $GLOBALS['app']->Layout->SetDescription($group['meta_description']);
     if (!is_numeric($gid)) {
         $gid = $group['id'];
     }
     $pages = $pModel->GetPages($gid, $limit, $orderBy, null, true);
     if (Jaws_Error::IsError($pages)) {
         return false;
     }
     $tpl = $this->gadget->template->load('StaticPage.html');
     $tpl->SetBlock('group_pages');
     $tpl->SetVariable('title', $group['title']);
     foreach ($pages as $page) {
         $param = array('gid' => empty($group['fast_url']) ? $group['id'] : $group['fast_url'], 'pid' => empty($page['fast_url']) ? $page['base_id'] : $page['fast_url']);
         $link = $this->gadget->urlMap('Pages', $param);
         $tpl->SetBlock('group_pages/item');
         $tpl->SetVariable('page', $page['title']);
         $tpl->SetVariable('link', $link);
         $tpl->ParseBlock('group_pages/item');
     }
     $tpl->ParseBlock('group_pages');
     return $tpl->Get();
 }
Beispiel #13
0
 /**
  * Updates file
  *
  * @access  public
  * @return  array   Response array
  */
 function UpdateFile()
 {
     try {
         // Validate data
         $data = jaws()->request->fetch(array('id', 'title', 'description', 'parent', 'hidden', 'user_filename', 'host_filename', 'filetype', 'filesize'));
         if (empty($data['title'])) {
             throw new Exception(_t('DIRECTORY_ERROR_INCOMPLETE_DATA'));
         }
         $data['title'] = Jaws_XSS::defilter($data['title']);
         $data['description'] = Jaws_XSS::defilter($data['description']);
         $model = $this->gadget->model->loadAdmin('Files');
         // Validate file
         $id = (int) $data['id'];
         $file = $model->GetFile($id);
         if (Jaws_Error::IsError($file)) {
             throw new Exception($file->getMessage());
         }
         // Upload file
         $path = $GLOBALS['app']->getDataURL('directory');
         if (!is_dir($path)) {
             if (!Jaws_Utils::mkdir($path, 2)) {
                 throw new Exception('DIRECTORY_ERROR_FILE_UPLOAD');
             }
         }
         $res = Jaws_Utils::UploadFiles($_FILES, $path, '', null);
         if (Jaws_Error::IsError($res)) {
             throw new Exception($res->getMessage());
         } else {
             if ($res !== false) {
                 $data['host_filename'] = $res['file'][0]['host_filename'];
                 $data['user_filename'] = $res['file'][0]['user_filename'];
                 $data['filetype'] = $res['file'][0]['host_filetype'];
                 $data['filesize'] = $res['file'][0]['host_filesize'];
             } else {
                 if ($data['host_filename'] === ':nochange:') {
                     unset($data['host_filename']);
                 } else {
                     if (empty($data['host_filename'])) {
                         throw new Exception(_t('DIRECTORY_ERROR_FILE_UPLOAD'));
                     } else {
                         $filename = Jaws_Utils::upload_tmp_dir() . '/' . $data['host_filename'];
                         if (file_exists($filename)) {
                             $target = $path . '/' . $data['host_filename'];
                             $res = Jaws_Utils::rename($filename, $target, false);
                             if ($res === false) {
                                 throw new Exception(_t('DIRECTORY_ERROR_FILE_UPLOAD'));
                             }
                             $data['host_filename'] = basename($res);
                         } else {
                             throw new Exception(_t('DIRECTORY_ERROR_FILE_UPLOAD'));
                         }
                     }
                 }
             }
         }
         // Update file in database
         unset($data['user']);
         $data['updatetime'] = time();
         $data['hidden'] = $data['hidden'] ? true : false;
         $model = $this->gadget->model->loadAdmin('Files');
         $res = $model->Update($id, $data);
         if (Jaws_Error::IsError($res)) {
             throw new Exception(_t('DIRECTORY_ERROR_FILE_UPDATE'));
         }
         // Update Tags
         if (Jaws_Gadget::IsGadgetInstalled('Tags')) {
             $tags = jaws()->request->fetch('tags');
             $tModel = Jaws_Gadget::getInstance('Tags')->model->loadAdmin('Tags');
             $tModel->UpdateReferenceTags('Directory', 'file', $id, !$data['hidden'], time(), $tags);
         }
     } catch (Exception $e) {
         return $GLOBALS['app']->Session->GetResponse($e->getMessage(), RESPONSE_ERROR);
     }
     return $GLOBALS['app']->Session->GetResponse(_t('DIRECTORY_NOTICE_FILE_UPDATED'), RESPONSE_NOTICE);
 }
Beispiel #14
0
 /**
  * Send contact reply
  *
  * @access  public
  * @param   int     $cid    Contact ID
  * @return  mixed   True on Success or Jaws_Error on Failure
  */
 function SendReply($cid)
 {
     $model = $this->gadget->model->loadAdmin('Contacts');
     $contact = $model->GetReply($cid);
     if (Jaws_Error::IsError($contact)) {
         $GLOBALS['app']->Session->PushLastResponse(_t('GLOBAL_ERROR_QUERY_FAILED'), RESPONSE_ERROR);
         return new Jaws_Error(_t('GLOBAL_ERROR_QUERY_FAILED'));
     }
     if (!isset($contact['id'])) {
         $GLOBALS['app']->Session->PushLastResponse(_t('CONTACT_ERROR_CONTACT_DOES_NOT_EXISTS'), RESPONSE_ERROR);
         return new Jaws_Error(_t('CONTACT_ERROR_CONTACT_DOES_NOT_EXISTS'));
     }
     $from_name = '';
     $from_email = '';
     $to = $contact['email'];
     $rid = $contact['recipient'];
     if ($rid != 0) {
         $rModel = $this->gadget->model->load('Recipients');
         $recipient = $rModel->GetRecipient($rid);
         if (Jaws_Error::IsError($recipient)) {
             $GLOBALS['app']->Session->PushLastResponse(_t('GLOBAL_ERROR_QUERY_FAILED'), RESPONSE_ERROR);
             return new Jaws_Error(_t('GLOBAL_ERROR_QUERY_FAILED'));
         }
         if (!isset($recipient['id'])) {
             $GLOBALS['app']->Session->PushLastResponse(_t('CONTACT_ERROR_RECIPIENT_DOES_NOT_EXISTS'), RESPONSE_ERROR);
             return new Jaws_Error(_t('CONTACT_ERROR_RECIPIENT_DOES_NOT_EXISTS'));
         }
         $from_name = $recipient['name'];
         $from_email = $recipient['email'];
     }
     $format = $this->gadget->registry->fetch('email_format');
     if ($format == 'html') {
         $reply = $this->gadget->ParseText($contact['reply']);
     } else {
         $reply = $contact['reply'];
     }
     $jDate = Jaws_Date::getInstance();
     $site_url = $GLOBALS['app']->getSiteURL('/');
     $site_name = $this->gadget->registry->fetch('site_name', 'Settings');
     $site_language = $this->gadget->registry->fetch('site_language', 'Settings');
     $profile_url = $GLOBALS['app']->getSiteURL('/') . $GLOBALS['app']->Map->GetURLFor('Users', 'Profile', array('user' => $GLOBALS['app']->Session->GetAttribute('username')));
     Jaws_Translate::getInstance()->LoadTranslation('Global', JAWS_COMPONENT_OTHERS, $site_language);
     Jaws_Translate::getInstance()->LoadTranslation('Contact', JAWS_COMPONENT_GADGET, $site_language);
     $tpl = $this->gadget->template->load('SendReplyTo.html', array('loadFromTheme' => true, 'loadRTLDirection' => _t_lang($site_language, 'GLOBAL_LANG_DIRECTION') == 'rtl'));
     $tpl->SetBlock($format);
     $tpl->SetVariable('lbl_name', _t_lang($site_language, 'GLOBAL_NAME'));
     $tpl->SetVariable('lbl_email', _t_lang($site_language, 'GLOBAL_EMAIL'));
     $tpl->SetVariable('lbl_message', _t_lang($site_language, 'CONTACT_MESSAGE'));
     $tpl->SetVariable('lbl_reply', _t_lang($site_language, 'CONTACT_REPLY'));
     $tpl->SetVariable('name', $contact['name']);
     $tpl->SetVariable('email', $contact['email']);
     $tpl->SetVariable('subject', $contact['subject']);
     $tpl->SetVariable('message', $contact['msg_txt']);
     $tpl->SetVariable('reply', $reply);
     $tpl->SetVariable('createtime', $jDate->Format($contact['createtime']));
     $tpl->SetVariable('nickname', $GLOBALS['app']->Session->GetAttribute('nickname'));
     $tpl->SetVariable('profile_url', $profile_url);
     $tpl->SetVariable('site-name', $site_name);
     $tpl->SetVariable('site-url', $site_url);
     $tpl->ParseBlock($format);
     $template = $tpl->Get();
     $subject = _t_lang($site_language, 'CONTACT_REPLY_TO', Jaws_XSS::defilter($contact['subject']));
     $mail = Jaws_Mail::getInstance();
     $mail->SetFrom($from_email, $from_name);
     $mail->AddRecipient($to);
     $mail->AddRecipient('', 'cc');
     $mail->SetSubject($subject);
     $mail->SetBody($template, $format);
     $result = $mail->send();
     if (Jaws_Error::IsError($result)) {
         $GLOBALS['app']->Session->PushLastResponse(_t('CONTACT_ERROR_REPLY_NOT_SENT'), RESPONSE_ERROR);
         return false;
     }
     $model->UpdateReplySent($cid, true);
     $GLOBALS['app']->Session->PushLastResponse(_t('CONTACT_REPLY_SENT'), RESPONSE_NOTICE);
     return true;
 }
Beispiel #15
0
 /**
  * Updates directory
  *
  * @access  public
  * @return  array   Response array
  */
 function UpdateDirectory()
 {
     try {
         $data = jaws()->request->fetch(array('title', 'description', 'parent'), 'post');
         // Validate data
         if (empty($data['title'])) {
             throw new Exception(_t('DIRECTORY_ERROR_INCOMPLETE_DATA'));
         }
         $data['title'] = Jaws_XSS::defilter($data['title']);
         $data['description'] = Jaws_XSS::defilter($data['description']);
         $id = (int) jaws()->request->fetch('id', 'post');
         $model = $this->gadget->model->load('Files');
         // Validate directory
         $dir = $model->GetFile($id);
         if (Jaws_Error::IsError($dir)) {
             throw new Exception($dir->getMessage());
         }
         // Validate user
         $user = (int) $GLOBALS['app']->Session->GetAttribute('user');
         if ($dir['user'] != $user) {
             throw new Exception(_t('DIRECTORY_ERROR_DIR_UPDATE'));
         }
         // Update directory
         $data['updatetime'] = time();
         $result = $model->Update($id, $data);
         if (Jaws_Error::IsError($result)) {
             throw new Exception(_t('DIRECTORY_ERROR_DIR_UPDATE'));
         }
         // Update shortcuts
         if ($dir['shared']) {
             $shortcut = array('updatetime' => $data['updatetime']);
             $model->UpdateShortcuts($id, $shortcut);
         }
     } catch (Exception $e) {
         return $GLOBALS['app']->Session->GetResponse($e->getMessage(), RESPONSE_ERROR);
     }
     return $GLOBALS['app']->Session->GetResponse(_t('DIRECTORY_NOTICE_DIR_UPDATED'), RESPONSE_NOTICE);
 }
Beispiel #16
0
 /**
  * Updates file
  *
  * @access  public
  * @return  array   Response array
  */
 function UpdateFile()
 {
     try {
         // Validate data
         $data = jaws()->request->fetch(array('id', 'title', 'description', 'parent', 'url', 'filename', 'filetype', 'filesize'));
         if (empty($data['title'])) {
             throw new Exception(_t('DIRECTORY_ERROR_INCOMPLETE_DATA'));
         }
         $data['title'] = Jaws_XSS::defilter($data['title']);
         $data['description'] = Jaws_XSS::defilter($data['description']);
         $model = $this->gadget->model->load('Files');
         // Validate file
         $id = (int) $data['id'];
         $file = $model->GetFile($id);
         if (Jaws_Error::IsError($file)) {
             throw new Exception($file->getMessage());
         }
         // Validate user
         $user = (int) $GLOBALS['app']->Session->GetAttribute('user');
         if ($file['user'] != $user) {
             throw new Exception(_t('DIRECTORY_ERROR_FILE_UPDATE'));
         }
         // Upload file
         if ($file['user'] != $file['owner']) {
             // is shortcut
             unset($data['parent'], $data['url'], $data['filename']);
             unset($data['filetype'], $data['filesize']);
         } else {
             $path = $GLOBALS['app']->getDataURL('directory/' . $user);
             if (!is_dir($path)) {
                 if (!Jaws_Utils::mkdir($path, 2)) {
                     throw new Exception('DIRECTORY_ERROR_FILE_UPLOAD');
                 }
             }
             $res = Jaws_Utils::UploadFiles($_FILES, $path);
             if (Jaws_Error::IsError($res)) {
                 throw new Exception($res->getMessage());
             } else {
                 if ($res !== false) {
                     $data['filename'] = $res['file'][0]['host_filename'];
                     $data['filetype'] = $res['file'][0]['host_filetype'];
                     $data['filesize'] = $res['file'][0]['host_filesize'];
                 } else {
                     if ($data['filename'] === ':nochange:') {
                         unset($data['filename']);
                     } else {
                         if (empty($data['filename'])) {
                             throw new Exception(_t('DIRECTORY_ERROR_FILE_UPLOAD'));
                         } else {
                             $filename = Jaws_Utils::upload_tmp_dir() . '/' . $data['filename'];
                             if (file_exists($filename)) {
                                 $target = $path . '/' . $data['filename'];
                                 $res = Jaws_Utils::rename($filename, $target, false);
                                 if ($res === false) {
                                     throw new Exception(_t('DIRECTORY_ERROR_FILE_UPLOAD'));
                                 }
                                 $data['filename'] = basename($res);
                             } else {
                                 throw new Exception(_t('DIRECTORY_ERROR_FILE_UPLOAD'));
                             }
                         }
                     }
                 }
             }
         }
         // Update file in database
         $data['updatetime'] = time();
         $model = $this->gadget->model->load('Files');
         $res = $model->Update($id, $data);
         if (Jaws_Error::IsError($res)) {
             throw new Exception(_t('DIRECTORY_ERROR_FILE_UPDATE'));
         }
         // Update shortcuts
         if ($file['shared']) {
             $shortcut = array();
             $shortcut['url'] = $data['url'];
             $shortcut['filename'] = $data['filename'];
             $shortcut['filetype'] = $data['filetype'];
             $shortcut['filesize'] = $data['filesize'];
             $shortcut['updatetime'] = $data['updatetime'];
             $model->UpdateShortcuts($id, $shortcut);
         }
     } catch (Exception $e) {
         return $GLOBALS['app']->Session->GetResponse($e->getMessage(), RESPONSE_ERROR);
     }
     return $GLOBALS['app']->Session->GetResponse(_t('DIRECTORY_NOTICE_FILE_UPDATED'), RESPONSE_NOTICE);
 }
Beispiel #17
0
 /**
  * Show edit post form
  *
  * @access  public
  * @param   bool    $reply              Reply mode
  * @param   string  $reply_to_message   Reply to message content
  * @return  string  XHTML template content
  */
 function EditPost($reply = false, $reply_to_message = '')
 {
     if (!$GLOBALS['app']->Session->Logged()) {
         return Jaws_HTTPError::Get(403);
     }
     $rqst = jaws()->request->fetch(array('fid', 'tid', 'pid', 'message', 'update_reason', 'notification'));
     if (empty($rqst['fid']) || empty($rqst['tid'])) {
         return false;
     }
     if (!$this->gadget->GetPermission('ForumPublic', $rqst['fid'])) {
         return Jaws_HTTPError::Get(403);
     }
     if ($reply || empty($rqst['pid'])) {
         $tModel = $this->gadget->model->load('Topics');
         $topic = $tModel->GetTopic($rqst['tid'], $rqst['fid']);
         if (Jaws_Error::IsError($topic) || empty($topic)) {
             return false;
         }
         $post = array();
         $post['id'] = 0;
         $post['fid'] = $topic['fid'];
         $post['tid'] = $topic['id'];
         $post['forum_title'] = $topic['forum_title'];
         $post['subject'] = $topic['subject'];
         $post['message'] = $reply_to_message;
         $post['update_reason'] = '';
         $title = _t('FORUMS_POSTS_NEW_TITLE');
         $btn_title = _t('FORUMS_POSTS_NEW_BUTTON');
     } else {
         $pModel = $this->gadget->model->load('Posts');
         $post = $pModel->GetPost($rqst['pid'], $rqst['tid'], $rqst['fid']);
         if (Jaws_Error::IsError($post) || empty($post)) {
             return false;
         }
         $title = _t('FORUMS_POSTS_EDIT_TITLE');
         $btn_title = _t('FORUMS_POSTS_EDIT_BUTTON');
     }
     $this->AjaxMe('site_script.js');
     $tpl = $this->gadget->template->load('EditPost.html');
     $tpl->SetBlock('post');
     $tpl->SetVariable('findex_title', _t('FORUMS_FORUMS'));
     $tpl->SetVariable('findex_url', $this->gadget->urlMap('Forums'));
     $tpl->SetVariable('forum_title', $post['forum_title']);
     $tpl->SetVariable('forum_url', $this->gadget->urlMap('Topics', array('fid' => $post['fid'])));
     $tpl->SetVariable('topic_title', $post['subject']);
     $tpl->SetVariable('topic_url', $this->gadget->urlMap('Posts', array('fid' => $post['fid'], 'tid' => $post['tid'])));
     $tpl->SetVariable('title', $title);
     $tpl->SetVariable('fid', $post['fid']);
     $tpl->SetVariable('tid', $post['tid']);
     $tpl->SetVariable('pid', $post['id']);
     // preview
     if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
         $post['message'] = $rqst['message'];
         $post['update_reason'] = $rqst['update_reason'];
         $tpl->SetBlock('post/preview');
         $tpl->SetVariable('lbl_preview', _t('GLOBAL_PREVIEW'));
         $tpl->SetVariable('message', $this->gadget->ParseText($post['message'], 'Forums', 'index'));
         $tpl->ParseBlock('post/preview');
     }
     if (!empty($post['id'])) {
         // date format
         $date_format = $this->gadget->registry->fetch('date_format');
         $date_format = empty($date_format) ? 'DN d MN Y' : $date_format;
         // post meta data
         $tpl->SetBlock('post/post_meta');
         $tpl->SetVariable('postedby_lbl', _t('FORUMS_POSTEDBY'));
         $tpl->SetVariable('username', $post['username']);
         $tpl->SetVariable('nickname', $post['nickname']);
         $tpl->SetVariable('user_url', $GLOBALS['app']->Map->GetURLFor('Users', 'Profile', array('user' => $post['username'])));
         $objDate = Jaws_Date::getInstance();
         $tpl->SetVariable('insert_time', $objDate->Format($post['insert_time'], $date_format));
         $tpl->SetVariable('insert_time_iso', $objDate->ToISO((int) $post['insert_time']));
         $tpl->ParseBlock('post/post_meta');
     }
     $rqst['notification'] = true;
     if ($response = $GLOBALS['app']->Session->PopResponse('UpdatePost')) {
         $tpl->SetVariable('type', $response['type']);
         $tpl->SetVariable('text', $response['text']);
         $post['message'] = $response['data']['message'];
         $rqst['notification'] = $response['data']['notification'];
     }
     // message
     $tpl->SetVariable('lbl_message', _t('FORUMS_POSTS_MESSAGE'));
     $message =& $GLOBALS['app']->LoadEditor('Forums', 'message', Jaws_XSS::defilter($post['message']), false);
     $message->setId('message');
     $message->TextArea->SetRows(8);
     $tpl->SetVariable('message', $message->Get());
     // attachment
     if ($this->gadget->registry->fetch('enable_attachment') == 'true' && $this->gadget->GetPermission('AddPostAttachment')) {
         $tpl->SetBlock('post/attachment');
         $tpl->SetVariable('lbl_attachment', _t('FORUMS_POSTS_ATTACHMENT'));
         $tpl->SetVariable('lbl_extra_attachment', _t('FORUMS_POSTS_EXTRA_ATTACHMENT'));
         $tpl->SetVariable('lbl_remove_attachment', _t('FORUMS_POSTS_ATTACHMENT_REMOVE'));
         if ($post['id'] != 0) {
             $aModel = $this->gadget->model->load('Attachments');
             $attachments = $aModel->GetAttachments($post['id']);
             foreach ($attachments as $attachment) {
                 $tpl->SetBlock('post/attachment/current_attachment');
                 $tpl->SetVariable('aid', $attachment['id']);
                 $tpl->SetVariable('lbl_filename', $attachment['title']);
                 $tpl->SetVariable('lbl_remove_attachment', _t('FORUMS_POSTS_ATTACHMENT_REMOVE'));
                 $tpl->ParseBlock('post/attachment/current_attachment');
             }
         }
         $tpl->ParseBlock('post/attachment');
     }
     // update reason
     if (!empty($post['id'])) {
         $tpl->SetBlock('post/update_reason');
         $tpl->SetVariable('lbl_update_reason', _t('FORUMS_POSTS_EDIT_REASON'));
         $tpl->SetVariable('update_reason', $post['update_reason']);
         $tpl->ParseBlock('post/update_reason');
     }
     // notification
     if ($this->gadget->GetPermission('ForumManage', $post['fid'])) {
         $tpl->SetBlock('post/notification');
         $tpl->SetVariable('lbl_send_notification', _t('FORUMS_NOTIFICATION_MESSAGE'));
         if ((bool) $rqst['notification']) {
             $tpl->SetBlock('post/notification/checked');
             $tpl->ParseBlock('post/notification/checked');
         }
         $tpl->ParseBlock('post/notification');
     }
     // check captcha only in new post action
     if (empty($rqst['pid'])) {
         $htmlPolicy = Jaws_Gadget::getInstance('Policy')->action->load('Captcha');
         $htmlPolicy->loadCaptcha($tpl, 'post');
     }
     // buttons
     $tpl->SetVariable('btn_update_title', $btn_title);
     $tpl->SetVariable('btn_preview_title', _t('GLOBAL_PREVIEW'));
     $tpl->SetVariable('btn_cancel_title', _t('GLOBAL_CANCEL'));
     $tpl->ParseBlock('post');
     return $tpl->Get();
 }
Beispiel #18
0
 /**
  * Sends the Email
  *
  * @access  public
  * @param   string  $target     JSON decoded array ([to, cc, bcc] or [user, group])
  * @param   string  $subject    Subject of the Email
  * @param   string  $message    Message body of the Email
  * @param   string  $attachment Attachment
  * @return  string  XHTML template content
  */
 function SendEmail($target, $subject, $message, $attachment)
 {
     $this->gadget->CheckPermission('AccessToMailer');
     $mail = Jaws_Mail::getInstance();
     $mail->SetFrom();
     $mail->SetSubject(Jaws_XSS::defilter($subject));
     // To, Cc, Bcc
     if (isset($target['to'])) {
         if (!empty($target['to'])) {
             $recipients = explode(',', $target['to']);
             foreach ($recipients as $recpt) {
                 $mail->AddRecipient($recpt, 'To');
             }
         }
         if (!empty($target['cc'])) {
             $recipients = explode(',', $target['cc']);
             foreach ($recipients as $recpt) {
                 $mail->AddRecipient($recpt, 'Cc');
             }
         }
         if (!empty($target['bcc'])) {
             $recipients = explode(',', $target['bcc']);
             foreach ($recipients as $recpt) {
                 $mail->AddRecipient($recpt, 'Bcc');
             }
         }
     } else {
         $userModel = new Jaws_User();
         if ($target['user'] != 0) {
             $user = $userModel->GetUser((int) $target['user']);
             if (!Jaws_Error::IsError($user)) {
                 $mail->AddRecipient($user['nickname'] . ' <' . $user['email'] . '>', 'To');
             }
         } else {
             if ($target['group'] == 0) {
                 $target['group'] = false;
             }
             $users = $userModel->GetUsers($target['group'], null, true);
             foreach ($users as $user) {
                 $mail->AddRecipient($user['nickname'] . ' <' . $user['email'] . '>', 'Bcc');
             }
         }
     }
     $message = $this->PrepareMessage($message);
     $format = $this->gadget->registry->fetch('email_format');
     $mail->SetBody($message, $format);
     if (!empty($attachment)) {
         $attachment = Jaws_Utils::upload_tmp_dir() . '/' . $attachment;
         if (file_exists($attachment)) {
             $mail->SetBody($attachment, 'file');
             Jaws_Utils::Delete($attachment);
         }
     }
     $result = $mail->send();
     if (Jaws_Error::IsError($result)) {
         $GLOBALS['app']->Session->PushLastResponse(_t('CONTACT_ERROR_EMAIL_NOT_SENT'), RESPONSE_ERROR);
         return false;
     }
     $GLOBALS['app']->Session->PushLastResponse(_t('CONTACT_NOTICE_EMAIL_SENT'), RESPONSE_NOTICE);
     return true;
 }
Beispiel #19
0
 /**
  * Displays meta settings form
  *
  * @access  public
  * @return  string  XHTML template content
  */
 function MetaSettings()
 {
     $this->gadget->CheckPermission('MetaSettings');
     $this->AjaxMe('script.js');
     $tpl = $this->gadget->template->loadAdmin('Settings.html');
     $tpl->SetBlock('settings');
     $tpl->SetVariable('base_script', BASE_SCRIPT);
     $tpl->SetVariable('sidebar', $this->SideBar('Meta'));
     $tpl->SetVariable('custom_meta', _t('SETTINGS_META_CUSTOM'));
     $tpl->SetVariable('legend', _t('SETTINGS_META_SETTINGS'));
     // Add Button
     $addButton =& Piwi::CreateWidget('Button', 'add', _t('SETTINGS_META_ADD_CUSTOM'), STOCK_ADD);
     $addButton->AddEvent(ON_CLICK, 'javascript:addCustomMeta();');
     $tpl->SetVariable('addButton', $addButton->Get());
     // Save Button
     $saveButton =& Piwi::CreateWidget('Button', 'save', _t('GLOBAL_SAVE'), STOCK_SAVE);
     $saveButton->AddEvent(ON_CLICK, 'javascript:submitMetaForm();');
     $tpl->SetVariable('saveButton', $saveButton->Get());
     // Site description
     $tpl->SetBlock('settings/item');
     $sitedesc =& Piwi::CreateWidget('TextArea', 'site_description', Jaws_XSS::defilter($this->gadget->registry->fetch('site_description')));
     $sitedesc->SetRows(5);
     $sitedesc->setID('site_description');
     $tpl->SetVariable('field-name', 'site_description');
     $tpl->SetVariable('label', _t('SETTINGS_SITE_DESCRIPTION'));
     $tpl->SetVariable('field', $sitedesc->Get());
     $tpl->ParseBlock('settings/item');
     // Site keywords
     $tpl->SetBlock('settings/item');
     $sitekeys =& Piwi::CreateWidget('Entry', 'site_keywords', $this->gadget->registry->fetch('site_keywords'));
     $sitekeys->setID('site_keywords');
     $sitekeys->setStyle('direction:ltr;');
     $tpl->SetVariable('field-name', 'site_keywords');
     $tpl->SetVariable('label', _t('SETTINGS_SITE_KEYWORDS'));
     $tpl->SetVariable('field', $sitekeys->Get());
     $tpl->ParseBlock('settings/item');
     // Site author
     $tpl->SetBlock('settings/item');
     $author =& Piwi::CreateWidget('Entry', 'site_author', $this->gadget->registry->fetch('site_author'));
     $author->setID('site_author');
     $tpl->SetVariable('field-name', 'site_author');
     $tpl->SetVariable('label', _t('SETTINGS_SITE_AUTHOR'));
     $tpl->SetVariable('field', $author->Get());
     $tpl->ParseBlock('settings/item');
     // License
     $tpl->SetBlock('settings/item');
     $license =& Piwi::CreateWidget('Entry', 'site_license', $this->gadget->registry->fetch('site_license'));
     $license->setID('site_license');
     $tpl->SetVariable('field-name', 'site_license');
     $tpl->SetVariable('label', _t('SETTINGS_SITE_LICENSE'));
     $tpl->SetVariable('field', $license->Get());
     $tpl->ParseBlock('settings/item');
     // Copyright
     $tpl->SetBlock('settings/item');
     $copyright =& Piwi::CreateWidget('Entry', 'site_copyright', $this->gadget->registry->fetch('site_copyright'));
     $copyright->setID('site_copyright');
     $tpl->SetVariable('field-name', 'site_copyright');
     $tpl->SetVariable('label', _t('SETTINGS_COPYRIGHT'));
     $tpl->SetVariable('field', $copyright->Get());
     $tpl->ParseBlock('settings/item');
     // Custom META
     $Metas = @unserialize($this->gadget->registry->fetch('site_custom_meta'));
     if (!empty($Metas)) {
         foreach ($Metas as $meta) {
             $tpl->SetBlock('settings/custom');
             $tpl->SetVariable('label', _t('SETTINGS_META_CUSTOM'));
             // name
             $nMeta =& Piwi::CreateWidget('Entry', 'meta_name', $meta[0]);
             $nMeta->setClass('meta-name');
             $tpl->SetVariable('name', $nMeta->Get());
             // value
             $vMeta =& Piwi::CreateWidget('Entry', 'meta_value', $meta[1]);
             $vMeta->setClass('meta-value');
             $tpl->SetVariable('value', $vMeta->Get());
             $tpl->ParseBlock('settings/custom');
         }
     }
     $tpl->ParseBlock('settings');
     return $tpl->Get();
 }
Beispiel #20
0
 /**
  * Displays general/basic settings form
  *
  * @access  public
  * @return  string  XHTML template content
  */
 function BasicSettings()
 {
     $this->gadget->CheckPermission('BasicSettings');
     $this->AjaxMe('script.js');
     $tpl = $this->gadget->template->loadAdmin('Settings.html');
     $tpl->SetBlock('settings');
     $tpl->SetVariable('base_script', BASE_SCRIPT);
     $tpl->SetVariable('sidebar', $this->SideBar('Basic'));
     $tpl->SetVariable('legend', _t('SETTINGS_BASIC_SETTINGS'));
     $saveButton =& Piwi::CreateWidget('Button', 'save', _t('GLOBAL_SAVE'), STOCK_SAVE);
     $saveButton->AddEvent(ON_CLICK, 'javascript:submitBasicForm();');
     $tpl->SetVariable('saveButton', $saveButton->Get());
     // site status
     $site_status =& Piwi::CreateWidget('Combo', 'site_status');
     $site_status->setID('site_status');
     $tpl->SetBlock('settings/item');
     $site_status->AddOption(_t('GLOBAL_DISABLED'), 'disabled');
     $site_status->AddOption(_t('GLOBAL_ENABLED'), 'enabled');
     $site_status->SetDefault($this->gadget->registry->fetch('site_status'));
     $tpl->SetVariable('field-name', 'site_status');
     $tpl->SetVariable('label', _t('SETTINGS_SITE_STATUS'));
     $tpl->SetVariable('field', $site_status->Get());
     $tpl->ParseBlock('settings/item');
     // Site name
     $tpl->SetBlock('settings/item');
     $sitename =& Piwi::CreateWidget('Entry', 'site_name', Jaws_XSS::defilter($this->gadget->registry->fetch('site_name')));
     $sitename->setID('site_name');
     $tpl->SetVariable('field-name', 'site_name');
     $tpl->SetVariable('label', _t('SETTINGS_SITE_NAME'));
     $tpl->SetVariable('field', $sitename->Get());
     $tpl->ParseBlock('settings/item');
     // Site slogan
     $tpl->SetBlock('settings/item');
     $sitedesc =& Piwi::CreateWidget('Entry', 'site_slogan', Jaws_XSS::defilter($this->gadget->registry->fetch('site_slogan')));
     $sitedesc->setID('site_slogan');
     $tpl->SetVariable('field-name', 'site_slogan');
     $tpl->SetVariable('label', _t('SETTINGS_SITE_SLOGAN'));
     $tpl->SetVariable('field', $sitedesc->Get());
     $tpl->ParseBlock('settings/item');
     // site language
     $lang =& Piwi::CreateWidget('Combo', 'site_language');
     $lang->setID('site_language');
     $tpl->SetBlock('settings/item');
     $languages = Jaws_Utils::GetLanguagesList();
     foreach ($languages as $k => $v) {
         $lang->AddOption($v, $k);
     }
     $lang->SetDefault($this->gadget->registry->fetch('site_language'));
     $tpl->SetVariable('field-name', 'site_language');
     $tpl->SetVariable('label', _t('SETTINGS_DEFAULT_SITE_LANGUAGE'));
     $tpl->SetVariable('field', $lang->Get());
     $tpl->ParseBlock('settings/item');
     // admin language
     $lang =& Piwi::CreateWidget('Combo', 'admin_language');
     $lang->setID('admin_language');
     $tpl->SetBlock('settings/item');
     foreach ($languages as $k => $v) {
         $lang->AddOption($v, $k);
     }
     $lang->SetDefault($this->gadget->registry->fetch('admin_language'));
     $tpl->SetVariable('field-name', 'admin_language');
     $tpl->SetVariable('label', _t('SETTINGS_ADMIN_LANGUAGE'));
     $tpl->SetVariable('field', $lang->Get());
     $tpl->ParseBlock('settings/item');
     // Main gadget
     $cmpModel = Jaws_Gadget::getInstance('Components')->model->load('Gadgets');
     $installedgadgets = $cmpModel->GetGadgetsList(null, true, true, true);
     $gdt =& Piwi::CreateWidget('Combo', 'main_gadget');
     $gdt->setID('main_gadget');
     $tpl->SetBlock('settings/item');
     $gdt->AddOption(_t('GLOBAL_NOGADGET'), '');
     foreach ($installedgadgets as $g => $tg) {
         $gdt->AddOption($tg['title'], $g);
     }
     $gdt->SetDefault($this->gadget->registry->fetch('main_gadget'));
     $tpl->SetVariable('field-name', 'main_gadget');
     $tpl->SetVariable('label', _t('SETTINGS_MAIN_GADGET'));
     $tpl->SetVariable('field', $gdt->Get());
     $tpl->ParseBlock('settings/item');
     // Site email
     $tpl->SetBlock('settings/item');
     $siteemail =& Piwi::CreateWidget('Entry', 'site_email', $this->gadget->registry->fetch('site_email'));
     $siteemail->setID('site_email');
     $tpl->SetVariable('field-name', 'site_email');
     $tpl->SetVariable('label', _t('SETTINGS_SITE_EMAIL'));
     $tpl->SetVariable('field', $siteemail->Get());
     $tpl->ParseBlock('settings/item');
     // Site comment
     $tpl->SetBlock('settings/item');
     $sitecomment =& Piwi::CreateWidget('TextArea', 'site_comment', Jaws_XSS::defilter($this->gadget->registry->fetch('site_comment')));
     $sitecomment->SetRows(4);
     $sitecomment->setID('site_comment');
     $tpl->SetVariable('field-name', 'site_comment');
     $tpl->SetVariable('label', _t('SETTINGS_SITE_COMMENT'));
     $tpl->SetVariable('field', $sitecomment->Get());
     $tpl->ParseBlock('settings/item');
     $tpl->ParseBlock('settings');
     return $tpl->Get();
 }
Beispiel #21
0
 /**
  * Displays a given blog entry
  *
  * @access  public
  * @param   int     $id                 Post id (optional, null by default)
  * @return  string  XHTML template content
  */
 function SingleView($id = null)
 {
     $g_id = jaws()->request->fetch('id', 'get');
     $g_id = Jaws_XSS::defilter($g_id);
     $model = $this->gadget->model->load('Posts');
     if (is_null($id)) {
         $entry = $model->GetEntry($g_id, true);
     } else {
         $entry = $model->GetEntry($id, true);
     }
     if (!Jaws_Error::IsError($entry) && !empty($entry)) {
         foreach ($entry['categories'] as $cat) {
             if (!$this->gadget->GetPermission('CategoryAccess', $cat['id'])) {
                 return Jaws_HTTPError::Get(403);
             }
         }
         //increase entry's visits counter
         $model->ViewEntry($entry['id']);
         $entry['clicks']++;
         if ($this->gadget->registry->fetch('pingback') == 'true') {
             $pback = Jaws_Pingback::getInstance();
             $pback->showHeaders($this->gadget->urlMap('Pingback', array(), true));
         }
         $this->SetTitle($entry['title']);
         $this->AddToMetaKeywords($entry['meta_keywords']);
         $this->SetDescription($entry['meta_description']);
         $tpl = $this->gadget->template->load('Post.html');
         $tpl->SetBlock('single_view');
         $this->ShowEntry($tpl, 'single_view', $entry, false);
         $trbkHTML = $this->gadget->action->load('Trackbacks');
         if (!Jaws_Error::IsError($trbkHTML)) {
             $tpl->SetVariable('trackbacks', $trbkHTML->ShowTrackbacks($entry['id']));
         }
         $allow_comments_config = $this->gadget->registry->fetch('allow_comments', 'Comments');
         switch ($allow_comments_config) {
             case 'restricted':
                 $allow_comments_config = $GLOBALS['app']->Session->Logged();
                 $restricted = !$allow_comments_config;
                 break;
             default:
                 $restricted = false;
                 $allow_comments_config = $allow_comments_config == 'true';
         }
         if (Jaws_Gadget::IsGadgetInstalled('Comments')) {
             $allow_comments = $entry['allow_comments'] === true && $this->gadget->registry->fetch('allow_comments') == 'true' && $allow_comments_config;
             $cHTML = Jaws_Gadget::getInstance('Comments')->action->load('Comments');
             $tpl->SetVariable('comments', $cHTML->ShowComments('Blog', 'Post', $entry['id'], array('action' => 'SingleView', 'params' => array('id' => empty($entry['fast_url']) ? $entry['id'] : $entry['fast_url']))));
             if ($allow_comments) {
                 $redirect_to = $this->gadget->urlMap('SingleView', array('id' => empty($entry['fast_url']) ? $entry['id'] : $entry['fast_url']));
                 $tpl->SetVariable('comment-form', $cHTML->ShowCommentsForm('Blog', 'Post', $entry['id'], $redirect_to));
             } elseif ($restricted) {
                 $login_url = $GLOBALS['app']->Map->GetURLFor('Users', 'LoginBox');
                 $register_url = $GLOBALS['app']->Map->GetURLFor('Users', 'Registration');
                 $tpl->SetVariable('comment-form', _t('COMMENTS_COMMENTS_RESTRICTED', $login_url, $register_url));
             }
         }
         if ($tpl->VariableExists('navigation')) {
             $navtpl = $this->gadget->template->load('PostNavigation.html');
             if ($prev = $model->GetNOPEntry($entry['id'], 'previous')) {
                 $navtpl->SetBlock('entry-navigation/previous');
                 $navtpl->SetVariable('url', $this->gadget->urlMap('SingleView', array('id' => empty($prev['fast_url']) ? $prev['id'] : $prev['fast_url'])));
                 $navtpl->SetVariable('title', $prev['title']);
                 $navtpl->SetVariable('previous', _t('GLOBAL_PREVIOUS'));
                 $navtpl->ParseBlock('entry-navigation/previous');
             }
             if ($next = $model->GetNOPEntry($entry['id'], 'next')) {
                 $navtpl->SetBlock('entry-navigation/next');
                 $navtpl->SetVariable('url', $this->gadget->urlMap('SingleView', array('id' => empty($next['fast_url']) ? $next['id'] : $next['fast_url'])));
                 $navtpl->SetVariable('title', $next['title']);
                 $navtpl->SetVariable('next', _t('GLOBAL_NEXT'));
                 $navtpl->ParseBlock('entry-navigation/next');
             }
             $navtpl->ParseBlock('entry-navigation');
             $tpl->SetVariable('navigation', $navtpl->Get());
         }
         $tpl->ParseBlock('single_view');
         return $tpl->Get();
     } else {
         return Jaws_HTTPError::Get(404);
     }
 }
Beispiel #22
0
 /**
  * Displays the weather of a specific region
  *
  * @access  public
  * @param   int      $region     Region ID
  * @param   bool     $forecast   Whether displays forecast or not
  * @return  string   XHTML content
  */
 function RegionWeather($region = null, $forecast = false)
 {
     $region_get = $this->gadget->request->fetch('id', 'get');
     $region_get = Jaws_XSS::defilter($region_get);
     if (!empty($region_get)) {
         $region = $region_get;
         $forecast = true;
     }
     $model = $this->gadget->model->load('Regions');
     $region = $model->GetRegion($region);
     if (Jaws_Error::IsError($region) || empty($region)) {
         return false;
     }
     $tpl = $this->gadget->template->load('Weather.html');
     $tpl->SetBlock('weather');
     $options = array();
     $options['timeout'] = (int) $this->gadget->registry->fetch('connection_timeout', 'Settings');
     if ($this->gadget->registry->fetch('proxy_enabled', 'Settings') == 'true') {
         if ($this->gadget->registry->fetch('proxy_auth', 'Settings') == 'true') {
             $options['proxy_user'] = $this->gadget->registry->fetch('proxy_user', 'Settings');
             $options['proxy_pass'] = $this->gadget->registry->fetch('proxy_pass', 'Settings');
         }
         $options['proxy_host'] = $this->gadget->registry->fetch('proxy_host', 'Settings');
         $options['proxy_port'] = $this->gadget->registry->fetch('proxy_port', 'Settings');
     }
     require_once JAWS_PATH . 'gadgets/Weather/include/Underground.php';
     $metric = $this->gadget->registry->fetchByUser('unit') == 'metric';
     $wService = new Underground_Weather($this->gadget->registry->fetch('api_key'), $metric, JAWS_DATA . 'weather', $this->gadget->registry->fetch('update_period'), $options);
     $rWeather = $wService->getWeather($region['latitude'], $region['longitude']);
     if (!PEAR::isError($rWeather)) {
         $tpl->SetVariable('title', _t('WEATHER_REGION', $region['title']));
         $rid = empty($region['fast_url']) ? $region['id'] : $region['fast_url'];
         $url = $this->gadget->urlMap('RegionWeather', array('id' => $rid));
         $tpl->SetVariable('url', $url);
         $tpl->SetBlock('weather/current');
         if ($forecast) {
             $tpl->SetBlock('weather/current/head');
             $tpl->SetVariable('lbl_current', _t('WEATHER_CURRENT'));
             $tpl->ParseBlock('weather/current/head');
         }
         $tpl->SetVariable('url', $url);
         $tpl->SetVariable('temp', $rWeather['temp']);
         $tpl->SetVariable('unit', $metric ? _t('WEATHER_UNIT_METRIC_TEMP') : _t('WEATHER_UNIT_IMPERIAL_TEMP'));
         $tpl->SetVariable('alt', $rWeather['icon']);
         $tpl->SetVariable('icon', "gadgets/Weather/Resources/images/states/{$rWeather['icon']}.png");
         $tpl->ParseBlock('weather/current');
         if ($forecast) {
             $GLOBALS['app']->Layout->SetTitle(_t('WEATHER_REGION', $region['title']));
             $GLOBALS['app']->Layout->AddToMetaKeywords($this->gadget->title . ',' . $region['title']);
             $objDate = Jaws_Date::getInstance();
             $tpl->SetBlock('weather/forecast');
             $tpl->SetVariable('lbl_forecast', _t('WEATHER_FORECAST'));
             $dFormat = $this->gadget->registry->fetchByUser('date_format');
             foreach ($rWeather['forecast'] as $dayIndex => $fWeather) {
                 $tpl->SetBlock('weather/forecast/item');
                 //86400 = 3600 * 24
                 $tpl->SetVariable('forecast_date', $objDate->Format(time() + $dayIndex * 86400, $dFormat));
                 $tpl->SetVariable('lbl_low', _t('WEATHER_LOW'));
                 $tpl->SetVariable('low_temp', $fWeather['low']);
                 $tpl->SetVariable('lbl_high', _t('WEATHER_HIGH'));
                 $tpl->SetVariable('high_temp', $fWeather['high']);
                 $tpl->SetVariable('unit', $metric ? _t('WEATHER_UNIT_METRIC_TEMP') : _t('WEATHER_UNIT_IMPERIAL_TEMP'));
                 $tpl->SetVariable('alt', $fWeather['icon']);
                 $tpl->SetVariable('icon', "gadgets/Weather/Resources/images/states/{$fWeather['icon']}.png");
                 $tpl->ParseBlock('weather/forecast/item');
             }
             $tpl->ParseBlock('weather/forecast');
         }
     } else {
         $GLOBALS['log']->Log(JAWS_LOG_ERROR, $rWeather->getMessage());
     }
     $tpl->ParseBlock('weather');
     return $tpl->Get();
 }
Beispiel #23
0
 /**
  * Updates directory
  *
  * @access  public
  * @return  array   Response array
  */
 function UpdateDirectory()
 {
     try {
         $data = jaws()->request->fetch(array('title', 'description', 'parent', 'hidden'), 'post');
         // Validate data
         if (empty($data['title'])) {
             throw new Exception(_t('DIRECTORY_ERROR_INCOMPLETE_DATA'));
         }
         $data['title'] = Jaws_XSS::defilter($data['title']);
         $data['description'] = Jaws_XSS::defilter($data['description']);
         $id = (int) jaws()->request->fetch('id', 'post');
         $model = $this->gadget->model->loadAdmin('Files');
         // Validate directory
         $dir = $model->GetFile($id);
         if (Jaws_Error::IsError($dir)) {
             throw new Exception($dir->getMessage());
         }
         // Update directory
         $data['update_time'] = time();
         $data['hidden'] = $data['hidden'] ? true : false;
         $result = $model->Update($id, $data);
         if (Jaws_Error::IsError($result)) {
             throw new Exception(_t('DIRECTORY_ERROR_DIR_UPDATE'));
         }
     } catch (Exception $e) {
         return $GLOBALS['app']->Session->GetResponse($e->getMessage(), RESPONSE_ERROR);
     }
     return $GLOBALS['app']->Session->GetResponse(_t('DIRECTORY_NOTICE_DIR_UPDATED'), RESPONSE_NOTICE);
 }
Beispiel #24
0
 /**
  * Action for providing download file
  *
  * @access  public
  * @return  string   Requested file content or HTML error page
  */
 function Download()
 {
     $id = jaws()->request->fetch('id', 'get');
     $id = Jaws_XSS::defilter($id);
     $fModel = $this->gadget->model->load('Files');
     $iFile = $fModel->DBFileInfoByIndex($id);
     if (Jaws_Error::IsError($iFile)) {
         $this->SetActionMode('Download', 'normal', 'standalone');
         return Jaws_HTTPError::Get(500);
     }
     if (!empty($iFile)) {
         $filepath = $fModel->GetFileBrowserRootDir() . $iFile['path'] . '/' . $iFile['filename'];
         if (file_exists($filepath)) {
             // increase download hits
             $fModel->HitFileDownload($iFile['id']);
             if (Jaws_Utils::Download($filepath, $iFile['filename'])) {
                 return;
             }
             $this->SetActionMode('Download', 'normal', 'standalone');
             return Jaws_HTTPError::Get(500);
         }
     }
     $this->SetActionMode('Download', 'normal', 'standalone');
     return Jaws_HTTPError::Get(404);
 }
Beispiel #25
0
 /**
  * Adds a new emblem
  *
  * @access  public
  * @see     EmblemsModel->AddEmblem()
  */
 function AddEmblem()
 {
     $post = jaws()->request->fetch(array('title', 'url', 'type', 'published'), 'post');
     $post['url'] = Jaws_XSS::defilter($post['url']);
     $res = Jaws_Utils::UploadFiles($_FILES, JAWS_DATA . 'emblems/', 'jpg,gif,swf,png,jpeg,bmp,svg');
     if (Jaws_Error::IsError($res)) {
         $GLOBALS['app']->Session->PushLastResponse($res->getMessage(), RESPONSE_ERROR);
     } elseif (empty($res)) {
         $GLOBALS['app']->Session->PushLastResponse(_t('EMBLEMS_ERROR_NO_IMAGE_UPLOADED'), RESPONSE_ERROR);
     } else {
         $post['image'] = $res['image'][0]['host_filename'];
         $post['published'] = (bool) $post['published'];
         $model = $this->gadget->model->loadAdmin('Emblems');
         $res = $model->AddEmblem($post);
         if (Jaws_Error::IsError($res)) {
             Jaws_Utils::delete(JAWS_DATA . 'emblems/' . $post['image']);
             $GLOBALS['app']->Session->PushLastResponse(_t('EMBLEMS_ERROR_NOT_ADDED'), RESPONSE_ERROR);
         } else {
             $GLOBALS['app']->Session->PushLastResponse(_t('EMBLEMS_ADDED'), RESPONSE_NOTICE);
         }
     }
     Jaws_Header::Location(BASE_SCRIPT . '?gadget=Emblems');
 }
Beispiel #26
0
 /**
  * Builds an individual page
  *
  * @access  public
  * @param   string  $base_action    Determines the map to be used (Page/Pages)
  * @return  string  XHTML content
  */
 function Page($pid = null, $base_action = 'Page')
 {
     $post = jaws()->request->fetch(array('gid', 'pid', 'language'), 'get');
     $post['gid'] = Jaws_XSS::defilter($post['gid']);
     $post['pid'] = empty($pid) ? Jaws_XSS::defilter($post['pid']) : $pid;
     $pModel = $this->gadget->model->load('Page');
     $gModel = $this->gadget->model->load('Group');
     $tModel = $this->gadget->model->load('Translation');
     if ($base_action == 'Pages') {
         $group = $gModel->GetGroup($post['gid']);
         if (Jaws_Error::IsError($group) || empty($group)) {
             return Jaws_HTTPError::Get(404);
         }
     }
     $page_id = empty($post['pid']) ? $this->gadget->registry->fetch('default_page') : $post['pid'];
     $page_language = $post['language'];
     if (empty($page_language)) {
         // if page language not set try to load language traslation of page that same as site language
         $page_language = $GLOBALS['app']->GetLanguage();
         if (!$tModel->TranslationExists($page_id, $page_language)) {
             $page_language = null;
         }
     }
     $page = $pModel->GetPage($page_id, $page_language);
     if (Jaws_Error::IsError($page) || empty($page) || !$page['published']) {
         return Jaws_HTTPError::Get(404);
     }
     if (!$this->gadget->GetPermission('AccessGroup', $page['group_id'])) {
         return Jaws_HTTPError::Get(403);
     }
     //add static page language to meta language tag
     $this->AddToMetaLanguages($page_language);
     $tpl = $this->gadget->template->load('StaticPage.html');
     $tpl->SetBlock('page');
     if (!$page['published'] && !$GLOBALS['app']->Session->IsSuperAdmin() && $page['user'] !== (int) $GLOBALS['app']->Session->GetAttribute('user')) {
         $this->SetTitle(_t('STATICPAGE_TITLE_NOT_FOUND'));
         $tpl->SetVariable('content', _t('STATICPAGE_CONTENT_NOT_FOUND'));
         $tpl->SetBlock('page/title');
         $tpl->SetVariable('title', _t('STATICPAGE_TITLE_NOT_FOUND'));
         $tpl->ParseBlock('page/title');
     } else {
         $this->SetTitle($page['title']);
         $this->AddToMetaKeywords($page['meta_keywords']);
         $this->SetDescription($page['meta_description']);
         $text = $this->gadget->ParseText($page['content']);
         $tpl->SetVariable('content', $text, false);
         if ($page['show_title']) {
             $tpl->SetBlock('page/title');
             $tpl->SetVariable('title', $page['title']);
             $tpl->ParseBlock('page/title');
         }
         if ($this->gadget->registry->fetch('multilanguage') == 'yes') {
             $translations = $tModel->GetTranslationsOfPage($page['page_id'], true);
             if (!Jaws_Error::isError($translations) && count($translations) > 1) {
                 $tpl->SetBlock('page/translations');
                 $tpl->SetVariable('avail_trans', _t('STATICPAGE_AVAIL_TRANSLATIONS'));
                 foreach ($translations as $trans) {
                     //if ($page['language'] == $trans['language']) continue;
                     $tpl->SetBlock('page/translations/language');
                     $tpl->SetVariable('lang', $trans['language']);
                     if ($base_action == 'Pages') {
                         $param = array('gid' => !empty($group['fast_url']) ? $group['fast_url'] : $group['id'], 'pid' => !empty($page['fast_url']) ? $page['fast_url'] : $page['page_id'], 'language' => $trans['language']);
                         $tpl->SetVariable('url', $this->gadget->urlMap('Pages', $param));
                     } else {
                         $param = array('pid' => !empty($page['fast_url']) ? $page['fast_url'] : $page['page_id'], 'language' => $trans['language']);
                         $tpl->SetVariable('url', $this->gadget->urlMap('Page', $param));
                     }
                     $tpl->ParseBlock('page/translations/language');
                 }
                 $tpl->ParseBlock('page/translations');
             }
         }
     }
     // Show Tags
     if (Jaws_Gadget::IsGadgetInstalled('Tags')) {
         $tagsHTML = Jaws_Gadget::getInstance('Tags')->action->load('Tags');
         $tagsHTML->loadReferenceTags('StaticPage', 'page', $page['translation_id'], $tpl, 'page');
     }
     $tpl->ParseBlock('page');
     return $tpl->Get();
 }
Beispiel #27
0
 /**
  * Checks if fast_url already exists in a table, if it doesn't then it returns
  * the original fast_url (the param value). However, if it already exists then 
  * it starts looking for a 'valid' fast_url using the 'foobar-[1...n]' schema.
  *
  * @access  protected
  * @param   string     $fast_url     Fast URL
  * @param   string     $table        DB table name (without [[ ]])
  * @param   bool       $unique_check must be false in update methods
  * @param   string     $field        Table field where fast_url is stored
  * @return  string     Correct fast URL
  */
 public function GetRealFastURL($fast_url, $table, $unique_check = true, $field = 'fast_url')
 {
     if (is_numeric($fast_url)) {
         $fast_url = '-' . $fast_url . '-';
     }
     $fast_url = Jaws_UTF8::trim(Jaws_XSS::defilter($fast_url));
     $fast_url = preg_replace(array('#[^\\p{L}[:digit:]_\\.\\-\\s]#u', '#[\\s_\\-]#u', '#\\-\\+#u'), array('', '-', '-'), Jaws_UTF8::strtolower($fast_url));
     $fast_url = Jaws_UTF8::substr($fast_url, 0, 90);
     if (!$unique_check) {
         return $fast_url;
     }
     $tblReg = Jaws_ORM::getInstance()->table($table);
     $result = $tblReg->select("count({$field})")->where($field, $fast_url . '%', 'like')->fetchOne();
     if (Jaws_Error::IsError($result) || empty($result)) {
         return $fast_url;
     }
     return $fast_url . '-' . $result;
 }
Beispiel #28
0
 /**
  * Displays titles of the feed sites
  *
  * @access  public
  * @param   int     $id     Feed site ID
  * @return  string  XHTML content with all titles and links of feed sites
  */
 function DisplayFeeds($id = 0)
 {
     if (empty($id)) {
         $id = $this->gadget->registry->fetch('default_feed');
     }
     $model = $this->gadget->model->load('Feed');
     $site = $model->GetFeed($id);
     if (Jaws_Error::IsError($site) || empty($site) || $site['visible'] == 0) {
         return false;
     }
     $tpl = $this->gadget->template->load('FeedReader.html');
     $tpl->SetBlock('feedreader');
     require_once JAWS_PATH . 'gadgets/FeedReader/include/XML_Feed.php';
     $parser = new XML_Feed();
     $parser->cache_time = $site['cache_time'];
     $options = array();
     $timeout = (int) $this->gadget->registry->fetch('connection_timeout', 'Settings');
     $options['timeout'] = $timeout;
     if ($this->gadget->registry->fetch('proxy_enabled', 'Settings') == 'true') {
         if ($this->gadget->registry->fetch('proxy_auth', 'Settings') == 'true') {
             $options['proxy_user'] = $this->gadget->registry->fetch('proxy_user', 'Settings');
             $options['proxy_pass'] = $this->gadget->registry->fetch('proxy_pass', 'Settings');
         }
         $options['proxy_host'] = $this->gadget->registry->fetch('proxy_host', 'Settings');
         $options['proxy_port'] = $this->gadget->registry->fetch('proxy_port', 'Settings');
     }
     $parser->setParams($options);
     if (Jaws_Utils::is_writable(JAWS_DATA . 'feedcache')) {
         $parser->cache_dir = JAWS_DATA . 'feedcache';
     }
     $res = $parser->fetch(Jaws_XSS::defilter($site['url']));
     if (PEAR::isError($res)) {
         $GLOBALS['log']->Log(JAWS_LOG_ERROR, '[' . $this->gadget->title . ']: ', _t('FEEDREADER_ERROR_CANT_FETCH', Jaws_XSS::refilter($site['url'])), '');
     }
     if (!isset($parser->feed)) {
         return false;
     }
     $block = $site['view_type'] == 0 ? 'simple' : 'marquee';
     $tpl->SetBlock("feedreader/{$block}");
     $tpl->SetVariable('title', _t('FEEDREADER_ACTION_TITLE'));
     switch ($site['title_view']) {
         case 1:
             $tpl->SetVariable('feed_title', Jaws_XSS::refilter($parser->feed['channel']['title']));
             $tpl->SetVariable('feed_link', Jaws_XSS::refilter(isset($parser->feed['channel']['link']) ? $parser->feed['channel']['link'] : ''));
             break;
         case 2:
             $tpl->SetVariable('feed_title', Jaws_XSS::refilter($site['title']));
             $tpl->SetVariable('feed_link', Jaws_XSS::refilter(isset($parser->feed['channel']['link']) ? $parser->feed['channel']['link'] : ''));
             break;
         default:
     }
     $tpl->SetVariable('marquee_direction', $site['view_type'] == 2 ? 'down' : ($site['view_type'] == 3 ? 'left' : ($site['view_type'] == 4 ? 'right' : 'up')));
     if (isset($parser->feed['items'])) {
         foreach ($parser->feed['items'] as $index => $item) {
             $tpl->SetBlock("feedreader/{$block}/item");
             $tpl->SetVariable('title', Jaws_XSS::refilter($item['title']));
             $tpl->SetVariable('href', isset($item['link']) ? Jaws_XSS::refilter($item['link']) : '');
             $tpl->ParseBlock("feedreader/{$block}/item");
             if ($site['count_entry'] > 0 && $site['count_entry'] <= $index + 1) {
                 break;
             }
         }
     }
     $tpl->ParseBlock("feedreader/{$block}");
     $tpl->ParseBlock('feedreader');
     return $tpl->Get();
 }
Beispiel #29
0
 /**
  * Send email to recipient
  *
  * @access  public
  * @param   string   $to   Recipient email address
  * @param   int      $cid   Contact ID
  * @return  mixed    True on Success or Jaws_Error on Failure
  */
 function SendEmailToRecipient($to, $cid)
 {
     $model = $this->gadget->model->load('Contacts');
     $contact = $model->GetContact($cid);
     if (Jaws_Error::IsError($contact)) {
         return $contact;
     }
     if (!isset($contact['id'])) {
         return new Jaws_Error(_t('CONTACT_ERROR_CONTACT_DOES_NOT_EXISTS'));
     }
     $from_name = $contact['name'];
     $from_email = $contact['email'];
     $site_url = $GLOBALS['app']->getSiteURL('/');
     $site_name = $this->gadget->registry->fetch('site_name', 'Settings');
     $format = $this->gadget->registry->fetch('email_format');
     if ($format == 'html') {
         $message = Jaws_String::AutoParagraph($contact['msg_txt']);
     } else {
         $message = $contact['msg_txt'];
     }
     $tpl = $this->gadget->template->load('SendToRecipient.html');
     $tpl->SetBlock($format);
     $tpl->SetVariable('lbl_name', _t('GLOBAL_NAME'));
     $tpl->SetVariable('lbl_email', _t('GLOBAL_EMAIL'));
     $tpl->SetVariable('lbl_company', _t('CONTACT_COMPANY'));
     $tpl->SetVariable('lbl_url', _t('GLOBAL_URL'));
     $tpl->SetVariable('lbl_tel', _t('CONTACT_TEL'));
     $tpl->SetVariable('lbl_fax', _t('CONTACT_FAX'));
     $tpl->SetVariable('lbl_mobile', _t('CONTACT_MOBILE'));
     $tpl->SetVariable('lbl_address', _t('CONTACT_ADDRESS'));
     $tpl->SetVariable('lbl_recipient', _t('CONTACT_RECIPIENT'));
     $tpl->SetVariable('lbl_subject', _t('CONTACT_SUBJECT'));
     $tpl->SetVariable('lbl_message', _t('CONTACT_MESSAGE'));
     $tpl->SetVariable('name', $contact['name']);
     $tpl->SetVariable('email', $contact['email']);
     $tpl->SetVariable('company', $contact['company']);
     $tpl->SetVariable('url', $contact['url']);
     $tpl->SetVariable('tel', $contact['tel']);
     $tpl->SetVariable('fax', $contact['fax']);
     $tpl->SetVariable('mobile', $contact['mobile']);
     $tpl->SetVariable('address', $contact['address']);
     $tpl->SetVariable('recipient', $to);
     $tpl->SetVariable('subject', $contact['subject']);
     $tpl->SetVariable('message', $message);
     $tpl->SetVariable('site-name', $site_name);
     $tpl->SetVariable('site-url', $site_url);
     $tpl->ParseBlock($format);
     $template = $tpl->Get();
     $mail = Jaws_Mail::getInstance();
     $mail->SetFrom($from_email, $from_name);
     $mail->AddRecipient($to);
     $mail->SetSubject(Jaws_XSS::defilter($contact['subject']));
     $mail->SetBody($template, $format);
     $result = $mail->send();
     if (Jaws_Error::IsError($result)) {
         return $result;
     }
     return true;
 }
Beispiel #30
0
 /**
  * Updates note
  *
  * @access  public
  * @return  array   Response array
  */
 function UpdateNote()
 {
     $data = jaws()->request->fetch(array('id', 'title', 'content'), 'post');
     if (empty($data['id']) || empty($data['title']) || empty($data['content'])) {
         $GLOBALS['app']->Session->PushResponse(_t('NOTEPAD_ERROR_INCOMPLETE_DATA'), 'Notepad.Response', RESPONSE_ERROR, $data);
         Jaws_Header::Referrer();
     }
     // Validate note
     $model = $this->gadget->model->load('Notepad');
     $id = (int) $data['id'];
     $user = (int) $GLOBALS['app']->Session->GetAttribute('user');
     $note = $model->GetNote($id, $user);
     if (Jaws_Error::IsError($note)) {
         $GLOBALS['app']->Session->PushResponse(_t('NOTEPAD_ERROR_RETRIEVING_DATA'), 'Notepad.Response', RESPONSE_ERROR);
         Jaws_Header::Referrer();
     }
     // Verify owner
     if ($note['user'] != $user) {
         $GLOBALS['app']->Session->PushResponse(_t('NOTEPAD_ERROR_NO_PERMISSION'), 'Notepad.Response', RESPONSE_ERROR);
         Jaws_Header::Referrer();
     }
     $data['title'] = Jaws_XSS::defilter($data['title']);
     $data['content'] = Jaws_XSS::defilter($data['content']);
     $result = $model->Update($id, $data);
     if (Jaws_Error::IsError($result)) {
         $GLOBALS['app']->Session->PushResponse(_t('NOTEPAD_ERROR_NOTE_UPDATE'), 'Notepad.Response', RESPONSE_ERROR, $data);
         Jaws_Header::Referrer();
     }
     $GLOBALS['app']->Session->PushResponse(_t('NOTEPAD_NOTICE_NOTE_UPDATED'), 'Notepad.Response');
     Jaws_Header::Location($this->gadget->urlMap('Notepad'));
 }