Example #1
0
File: Search.php Project: uda/jaws
 /**
  * Returns an array with the results of a search
  *
  * @access  public
  * @param   string  $pSql   Prepared search(WHERE) SQL
  * @return  array   An array of entries that matches a certain pattern
  */
 function Execute($pSql = '')
 {
     $sql = '
         SELECT
            [id], [title], [description], [user_filename], [update_time]
         FROM [[directory]]
         WHERE
             [hidden] = {hidden}
         ';
     $sql .= ' AND ' . $pSql;
     $sql .= ' ORDER BY id desc';
     $params = array();
     $params['hidden'] = false;
     $types = array('text', 'text', 'text', 'integer');
     $result = Jaws_DB::getInstance()->queryAll($sql, $params, $types);
     if (Jaws_Error::IsError($result)) {
         return array();
     }
     $date = Jaws_Date::getInstance();
     $files = array();
     foreach ($result as $p) {
         $file = array();
         $file['title'] = $p['title'];
         $file['url'] = $this->gadget->urlMap('Directory', array('id' => $p['id']));
         $file['image'] = 'gadgets/Directory/Resources/images/logo.png';
         $file['snippet'] = $p['description'];
         $file['date'] = $p['update_time'];
         $stamp = $p['update_time'];
         $files[$stamp] = $file;
     }
     return $files;
 }
Example #2
0
 /**
  * Get registry settings for Phoo
  *
  * @access  public
  * @return  mixed    array with the settings or Jaws_Error on error
  */
 function GetSettings()
 {
     $ret = array();
     $ret['default_action'] = $this->gadget->registry->fetch('default_action');
     $ret['resize_method'] = $this->gadget->registry->fetch('resize_method');
     $ret['moblog_album'] = $this->gadget->registry->fetch('moblog_album');
     $ret['moblog_limit'] = $this->gadget->registry->fetch('moblog_limit');
     $ret['photoblog_album'] = $this->gadget->registry->fetch('photoblog_album');
     $ret['photoblog_limit'] = $this->gadget->registry->fetch('photoblog_limit');
     $ret['allow_comments'] = $this->gadget->registry->fetch('allow_comments');
     $ret['published'] = $this->gadget->registry->fetch('published');
     $ret['show_exif_info'] = $this->gadget->registry->fetch('show_exif_info');
     $ret['keep_original'] = $this->gadget->registry->fetch('keep_original');
     $ret['thumbnail_limit'] = $this->gadget->registry->fetch('thumbnail_limit');
     $ret['comment_status'] = $this->gadget->registry->fetch('comment_status');
     $ret['use_antispam'] = $this->gadget->registry->fetch('use_antispam');
     $ret['albums_order_type'] = $this->gadget->registry->fetch('albums_order_type');
     $ret['photos_order_type'] = $this->gadget->registry->fetch('photos_order_type');
     foreach ($ret as $r) {
         if (Jaws_Error::IsError($r)) {
             if (isset($GLOBALS['app']->Session)) {
                 $GLOBALS['app']->Session->PushLastResponse(_t('PHOO_ERROR_CANT_FETCH_SETTINGS'), RESPONSE_ERROR);
             }
             return new Jaws_Error(_t('PHOO_ERROR_CANT_FETCH_SETTINGS'));
         }
     }
     return $ret;
 }
Example #3
0
 /**
  * Displays the captcha image
  *
  * @access  public
  * @param   int     $key    Captcha key
  * @return  mixed   Captcha raw image data
  */
 function image($key)
 {
     $value = Jaws_Utils::RandomText();
     $result = $this->update($key, $value);
     if (Jaws_Error::IsError($result)) {
         $value = '';
     }
     $bg = dirname(__FILE__) . '/resources/simple.bg.png';
     $im = imagecreatefrompng($bg);
     imagecolortransparent($im, imagecolorallocate($im, 255, 255, 255));
     // Write it in a random position..
     $darkgray = imagecolorallocate($im, 0x10, 0x70, 0x70);
     $x = 5;
     $y = 20;
     $text_length = strlen($value);
     for ($i = 0; $i < $text_length; $i++) {
         $fnt = rand(7, 10);
         $y = rand(6, 10);
         imagestring($im, $fnt, $x, $y, $value[$i], $darkgray);
         $x = $x + rand(15, 25);
     }
     header("Content-Type: image/png");
     ob_start();
     imagepng($im);
     $content = ob_get_contents();
     ob_end_clean();
     imagedestroy($im);
     return $content;
 }
Example #4
0
 /**
  * Authenticate user/password
  *
  * @access  public
  * @param   string  $user       User's name or email
  * @param   string  $password   User's password
  * @return  mixed   Array of user's information otherwise Jaws_Error
  */
 function Auth($user, $password)
 {
     if (!function_exists('imap_open')) {
         return Jaws_Error::raiseError('Undefined function imap_open()', __FUNCTION__);
     }
     $mbox = @imap_open('{' . $this->_Server . ':' . $this->_Port . ($this->_SSL ? '/imap/ssl' : '') . '}INBOX', $user, $password);
     if ($mbox) {
         @imap_close($mbox);
         $result = array();
         $result['id'] = strtolower('imap:' . $user);
         $result['internal'] = false;
         $result['username'] = $user;
         $result['superadmin'] = false;
         $result['internal'] = false;
         $result['groups'] = array();
         $result['nickname'] = $user;
         $result['concurrents'] = 0;
         $result['email'] = '';
         $result['url'] = '';
         $result['avatar'] = 'gadgets/Users/Resources/images/photo48px.png';
         $result['language'] = '';
         $result['theme'] = '';
         $result['editor'] = '';
         $result['timezone'] = null;
         return $result;
     }
     return Jaws_Error::raiseError(_t('GLOBAL_ERROR_LOGIN_WRONG'), __FUNCTION__);
 }
Example #5
0
 /**
  * Returns an array with the results of a search
  *
  * @access  public
  * @param   string  $pSql  Prepared search (WHERE) SQL
  * @return  array   An array of entries that matches a certain pattern
  */
 function Execute($pSql = '')
 {
     // TODO: must be converted to Jaws_ORM
     $sql = '
         SELECT
             [id], [title], [contents], [updatetime]
         FROM [[blocks]]
         ';
     $sql .= ' WHERE ' . $pSql;
     $sql .= ' ORDER BY [createtime] desc';
     $result = Jaws_DB::getInstance()->queryAll($sql);
     if (Jaws_Error::IsError($result)) {
         return array();
     }
     $date = Jaws_Date::getInstance();
     $blocks = array();
     foreach ($result as $r) {
         $block = array();
         $block['title'] = $r['title'];
         $block['url'] = $this->gadget->urlMap('Block', array('id' => $r['id']));
         $block['image'] = 'gadgets/Blocks/Resources/images/logo.png';
         $block['snippet'] = $r['contents'];
         $block['date'] = $date->ToISO($r['updatetime']);
         $blocks[] = $block;
     }
     return $blocks;
 }
Example #6
0
 /**
  * Returns an array of the search results
  *
  * @access  public
  * @param   string  $pSql  Prepared search(WHERE) SQL
  * @return  array   Array of entries match a certain pattern
  */
 function Execute($pSql = '')
 {
     $sql = '
         SELECT
             [id], [title], [quotation], [updatetime]
         FROM [[quotes]]
         WHERE [published] = {published}
         ';
     $sql .= ' AND ' . $pSql;
     $sql .= ' ORDER BY [id] desc';
     $params = array();
     $params['published'] = true;
     $result = Jaws_DB::getInstance()->queryAll($sql, $params);
     if (Jaws_Error::IsError($result)) {
         return array();
     }
     $date = Jaws_Date::getInstance();
     $quotations = array();
     foreach ($result as $r) {
         $quotation = array();
         $quotation['title'] = $r['title'];
         $quotation['url'] = $this->gadget->urlMap('ViewQuote', array('id' => $r['id']));
         $quotation['image'] = 'gadgets/Quotes/Resources/images/logo.png';
         $quotation['snippet'] = $r['quotation'];
         $quotation['date'] = $date->ToISO($r['updatetime']);
         $quotations[] = $quotation;
     }
     return $quotations;
 }
Example #7
0
 /**
  * Validates any data provided to the stage.
  *
  * @access  public
  * @return  bool|Jaws_Error  Returns either true on success, or a Jaws_Error
  *                          containing the reason for failure.
  */
 function Validate()
 {
     if ($_SESSION['install']['predefined']) {
         return true;
     }
     $request = Jaws_Request::getInstance();
     $postReq = $request->fetch(array('secure', 'customize'), 'post');
     $_SESSION['secure'] = !empty($postReq['secure']);
     $_SESSION['customize'] = !empty($postReq['customize']);
     // try to entering to secure transformation mode
     if ($_SESSION['secure'] && (!isset($_SESSION['pub_key']) || empty($_SESSION['pub_key']))) {
         require_once JAWS_PATH . 'include/Jaws/Crypt.php';
         $pkey = Jaws_Crypt::Generate_RSA_KeyPair(512);
         if (!Jaws_Error::isError($pkey)) {
             $_SESSION['pub_key'] = $pkey['pub_key'];
             $_SESSION['pvt_key'] = $pkey['pvt_key'];
         } else {
             return new Jaws_Error(_t('INSTALL_AUTH_ERROR_RSA_KEY_GENERATION'), 0, JAWS_ERROR_WARNING);
         }
     }
     $key_file = INSTALL_PATH . 'key.txt';
     if (file_exists($key_file)) {
         $key = trim(file_get_contents($key_file));
         if ($key === $_SESSION['install']['Authentication']['key']) {
             _log(JAWS_LOG_DEBUG, "Input log and session key match");
             return true;
         }
         _log(JAWS_LOG_DEBUG, "The key found doesn't match the one below, please check that you entered the key correctly");
         return new Jaws_Error(_t('INSTALL_AUTH_ERROR_KEY_MATCH', 'key.txt'), 0, JAWS_ERROR_WARNING);
     }
     _log(JAWS_LOG_DEBUG, "Your key file was not found, please make sure you created it, and the web server is able to read it.");
     return new Jaws_Error(_t('INSTALL_AUTH_ERROR_KEY_FILE', 'key.txt'), 0, JAWS_ERROR_WARNING);
 }
Example #8
0
 /**
  *
  * @access  public
  * @return  string HTML content with menu and menu items
  */
 function LoginHistory($limit = 5)
 {
     if (!$GLOBALS['app']->Session->Logged()) {
         return false;
     }
     $logModel = Jaws_Gadget::getInstance('Logs')->model->load('Logs');
     $logs = $logModel->GetLogs(array('gadget' => 'Users', 'action' => 'Login', 'user' => $GLOBALS['app']->Session->GetAttribute('user')), $limit);
     if (Jaws_Error::IsError($logs) || empty($logs)) {
         return false;
     }
     $tpl = $this->gadget->template->load('LoginHistory.html');
     $tpl->SetBlock('history');
     $date = Jaws_Date::getInstance();
     $tpl->SetVariable('title', _t('LOGS_LOGIN_HISTORY'));
     foreach ($logs as $log) {
         $tpl->SetBlock('history/' . $log['status']);
         $tpl->SetVariable('ip', long2ip($log['ip']));
         $tpl->SetVariable('agent', $log['agent']);
         $tpl->SetVariable('status_title', _t('GLOBAL_HTTP_ERROR_TITLE_' . $log['status']));
         $tpl->SetVariable('date', $date->Format($log['insert_time'], 'd MN Y H:i'));
         $tpl->ParseBlock('history/' . $log['status']);
     }
     $tpl->ParseBlock('history');
     return $tpl->Get();
 }
Example #9
0
 /**
  * Update user rate of a reference item
  *
  * @access  public
  * @param   string  $gadget     Gadget name
  * @param   string  $action     Action name
  * @param   int     $reference  Reference
  * @param   int     $item       Rating item
  * @param   int     $rate       User rate(if null user old rate will be removed)
  * @return  mixed   Rate value or Jaws_Error on failure
  */
 function UpdateUserRating($gadget, $action, $reference, $item = 0, $rate = null)
 {
     $objORM = Jaws_ORM::getInstance();
     // fetch reference item from parent table(rating)
     $rid = $objORM->table('rating')->upsert(array('gadget' => $gadget, 'action' => $action, 'reference' => $reference, 'item' => $item))->where('gadget', $gadget)->and()->where('action', $action)->and()->where('reference', $reference)->and()->where('item', $item)->exec();
     if (Jaws_Error::IsError($rid)) {
         return $rid;
     }
     // insert/update user rate
     $uip = bin2hex(inet_pton($_SERVER['REMOTE_ADDR']));
     $objORM->beginTransaction();
     if (is_null($rate)) {
         // delete user rate
         $result = $objORM->table('rating_details')->delete()->where('rid', $rid)->and()->where('uip', $uip)->exec();
     } else {
         // update/insert user rate
         $result = $objORM->table('rating_details')->upsert(array('rid' => $rid, 'uip' => $uip, 'rate' => (int) $rate))->where('rid', $rid)->and()->where('uip', $uip)->exec();
     }
     if (Jaws_Error::IsError($result)) {
         return $result;
     }
     // update rating statistics
     $result = $objORM->table('rating')->update(array('rates_count' => Jaws_ORM::getInstance()->table('rating_details')->select('count(id)')->where('rid', $rid), 'rates_sum' => Jaws_ORM::getInstance()->table('rating_details')->select('sum(rate)')->where('rid', $rid), 'rates_avg' => Jaws_ORM::getInstance()->table('rating_details')->select('avg(rate)')->where('rid', $rid)))->where('id', $rid)->exec();
     if (Jaws_Error::IsError($result)) {
         return $result;
     }
     //commit transaction
     $objORM->commit();
     return true;
 }
Example #10
0
 /**
  * Displays a random image from one of the galleries.
  *
  * @access  public
  * @param   int     $albumid    album ID
  * @return  string   XHTML template content
  * @see Phoo_Model::GetRandomImage()
  */
 function Random($albumid = null)
 {
     $model = $this->gadget->model->load('Random');
     $r = $model->GetRandomImage($albumid);
     if (Jaws_Error::IsError($r) || empty($r)) {
         return false;
     }
     $tpl = $this->gadget->template->load('Random.html');
     $tpl->SetBlock('random_image');
     $imgData = Jaws_Image::getimagesize(JAWS_DATA . 'phoo/' . $r['thumb']);
     if (!Jaws_Error::IsError($imgData)) {
         $tpl->SetVariable('width', $imgData[0]);
         $tpl->SetVariable('height', $imgData[1]);
     }
     $tpl->SetVariable('title', _t('PHOO_ACTIONS_RANDOM'));
     $tpl->SetVariable('url', $this->gadget->urlMap('ViewImage', array('id' => $r['id'], 'albumid' => $r['phoo_album_id'])));
     $tpl->SetVariable('name', $r['name']);
     $tpl->SetVariable('filename', $r['filename']);
     $tpl->SetVariable('thumb', $GLOBALS['app']->getDataURL('phoo/' . $r['thumb']));
     $tpl->SetVariable('medium', $GLOBALS['app']->getDataURL('phoo/' . $r['medium']));
     $tpl->SetVariable('image', $GLOBALS['app']->getDataURL('phoo/' . $r['image']));
     $tpl->SetVariable('img_desc', $r['stripped_description']);
     $tpl->ParseBlock('random_image');
     return $tpl->Get();
 }
Example #11
0
 /**
  * Download post attachment
  *
  * @access  public
  * @return  string   Requested file content or HTML error page
  */
 function Attachment()
 {
     $rqst = jaws()->request->fetch(array('fid', 'tid', 'pid', 'attach'), 'get');
     $pModel = $this->gadget->model->load('Posts');
     $post = $pModel->GetPost($rqst['pid'], $rqst['tid'], $rqst['fid']);
     if (Jaws_Error::IsError($post)) {
         $this->SetActionMode('Attachment', 'normal', 'standalone');
         return Jaws_HTTPError::Get(500);
     }
     $aModel = $this->gadget->model->load('Attachments');
     $attachment = $aModel->GetAttachmentInfo($rqst['attach']);
     if (Jaws_Error::IsError($attachment)) {
         $this->SetActionMode('Attachment', 'normal', 'standalone');
         return Jaws_HTTPError::Get(500);
     }
     if (!empty($attachment)) {
         $filepath = JAWS_DATA . 'forums/' . $attachment['filename'];
         if (file_exists($filepath)) {
             // increase download hits
             $result = $aModel->HitAttachmentDownload($rqst['attach']);
             if (Jaws_Error::IsError($result)) {
                 // do nothing
             }
             if (Jaws_Utils::Download($filepath, $attachment['title'])) {
                 return;
             }
             $this->SetActionMode('Attachment', 'normal', 'standalone');
             return Jaws_HTTPError::Get(500);
         }
     }
     $this->SetActionMode('Attachment', 'normal', 'standalone');
     return Jaws_HTTPError::Get(404);
 }
Example #12
0
 /**
  * Returns an array with the results of a search
  *
  * @access  public
  * @param   string  $pSql  Prepared search (WHERE) SQL
  * @return  mixed   An array of entries that matches a certain pattern or False on error
  */
 function Execute($pSql = '')
 {
     $sql = '
         SELECT
             [id], [term], [description], [createtime]
         FROM [[glossary]]
         ';
     $sql .= ' WHERE ' . $pSql;
     $sql .= " ORDER BY [createtime] desc";
     $result = Jaws_DB::getInstance()->queryAll($sql);
     if (Jaws_Error::IsError($result)) {
         return false;
     }
     $date = Jaws_Date::getInstance();
     $entries = array();
     foreach ($result as $r) {
         $entry = array();
         $entry['title'] = $r['term'];
         $entry['url'] = $this->gadget->urlMap('ViewTerm', array('term' => $r['id']));
         $entry['image'] = 'gadgets/Glossary/Resources/images/logo.png';
         $entry['snippet'] = $r['description'];
         $entry['date'] = $date->ToISO($r['createtime']);
         $stamp = str_replace(array('-', ':', ' '), '', $r['createtime']);
         $entries[$stamp] = $entry;
     }
     return $entries;
 }
Example #13
0
 /**
  * Upgrades the gadget
  *
  * @access  public
  * @param   string  $old    Current version (in registry)
  * @param   string  $new    New version (in the $gadgetInfo file)
  * @return  mixed   True on success, Jaws_Error otherwise
  */
 function Upgrade($old, $new)
 {
     if (version_compare($old, '2.0.0', '<')) {
         $variables = array();
         $variables['logon_hours'] = str_pad('', 42, 'F');
         $result = $this->installSchema('schema.xml', $variables, '1.0.0.xml');
         if (Jaws_Error::IsError($result)) {
             return $result;
         }
         // update users passwords
         $usersTable = Jaws_ORM::getInstance()->table('users');
         $usersTable->update(array('password' => $usersTable->concat(array('{SSHA1}', 'text'), 'password')))->where($usersTable->length('password'), 32, '>')->exec();
         $usersTable->update(array('password' => $usersTable->concat(array('{MD5}', 'text'), 'password')))->where($usersTable->length('password'), 32)->exec();
         // ACL keys
         $this->gadget->acl->insert('ManageFriends');
         $this->gadget->acl->insert('AccessDashboard');
         $this->gadget->acl->insert('ManageDashboard');
     }
     if (version_compare($old, '2.1.0', '<')) {
         $this->gadget->registry->delete('anon_repetitive_email');
     }
     if (version_compare($old, '2.2.0', '<')) {
         $result = $this->installSchema('schema.xml', '', '2.1.0.xml');
         if (Jaws_Error::IsError($result)) {
             return $result;
         }
     }
     return true;
 }
Example #14
0
 /**
  * Builds UI for the plugin information
  *
  * @access  public
  * @param   string   $plugin  Plugin's name
  * @return  string   XHTML UI
  */
 function PluginInfo($plugin)
 {
     $objPlugin = $GLOBALS['app']->LoadPlugin($plugin);
     if (Jaws_Error::IsError($objPlugin)) {
         return $objPlugin->getMessage();
     }
     $tpl = $this->gadget->template->loadAdmin('Plugin.html');
     $tpl->SetBlock('info');
     $tpl->SetVariable('lbl_version', _t('COMPONENTS_VERSION') . ':');
     $tpl->SetVariable('lbl_example', _t('COMPONENTS_PLUGINS_USAGE') . ':');
     $tpl->SetVariable('lbl_accesskey', _t('COMPONENTS_PLUGINS_ACCESSKEY') . ':');
     $tpl->SetVariable('lbl_friendly', _t('COMPONENTS_PLUGINS_FRIENDLY') . ':');
     $tpl->SetVariable('accesskey', $objPlugin->GetAccessKey() ? $objPlugin->GetAccessKey() : _t('COMPONENTS_PLUGINS_NO_ACCESSKEY'));
     $tpl->SetVariable('friendly', $objPlugin->friendly ? _t('COMPONENTS_PLUGINS_FRIENDLY') : _t('COMPONENTS_PLUGINS_NOT_FRIENDLY'));
     $tpl->SetVariable('example', $objPlugin->example ? $objPlugin->example : _t('COMPONENTS_PLUGINS_NO_EXAMPLE'));
     $tpl->SetVariable('version', $objPlugin->version);
     $button =& Piwi::CreateWidget('Button', 'btn_install', _t('COMPONENTS_INSTALL'), STOCK_SAVE);
     $button->AddEvent(ON_CLICK, 'javascript:setupComponent();');
     $button->SetStyle('display:none');
     $tpl->SetVariable('install', $button->Get());
     $button =& Piwi::CreateWidget('Button', 'btn_uninstall', _t('COMPONENTS_UNINSTALL'), STOCK_DELETE);
     $button->AddEvent(ON_CLICK, 'javascript:setupComponent();');
     $button->SetStyle('display:none');
     $tpl->SetVariable('uninstall', $button->Get());
     $tpl->ParseBlock('info');
     return $tpl->Get();
 }
Example #15
0
 /**
  * Get the poll results
  *
  * @access  public
  * @param   int     $pid    Poll ID
  * @return  string  XHTML template content
  */
 function PollResultsUI($pid)
 {
     $tpl = $this->gadget->template->loadAdmin('Reports.html');
     $tpl->SetBlock('PollResults');
     $model = $this->gadget->model->load('Poll');
     $poll = $model->GetPoll($pid);
     if (Jaws_Error::IsError($poll)) {
         //we need to handle errors
         return '';
     }
     $answers = $model->GetPollAnswers($poll['id']);
     if (!Jaws_Error::IsError($answers)) {
         $total_votes = array_sum(array_map(create_function('$row', 'return $row["votes"];'), $answers));
         $tpl->SetVariable('lbl_total_votes', _t('POLL_REPORTS_TOTAL_VOTES'));
         $tpl->SetVariable('total_votes', $total_votes);
         foreach ($answers as $answer) {
             $tpl->SetBlock('PollResults/answer');
             $tpl->SetVariable('answer', $answer['answer']);
             $percent = $total_votes == 0 ? 0 : floor($answer['votes'] / $total_votes * 100);
             $tpl->SetVariable('percent', _t('POLL_REPORTS_PERCENT', $percent));
             $tpl->SetVariable('image_width', floor($percent * 1.5));
             $tpl->SetVariable('votes', $answer['votes']);
             $tpl->ParseBlock('PollResults/answer');
         }
     }
     $tpl->ParseBlock('PollResults');
     return $tpl->Get();
 }
Example #16
0
 /**
  * Deletes passed note(s)
  *
  * @access  public
  * @return  mixed   Response array
  */
 function DeleteNote()
 {
     $id_set = jaws()->request->fetch('id_set');
     $id_set = explode(',', $id_set);
     if (empty($id_set)) {
         return $GLOBALS['app']->Session->GetResponse(_t('NOTEPAD_ERROR_NOTE_DELETE'), RESPONSE_ERROR);
     }
     // Verify notes & user
     $model = $this->gadget->model->load('Notepad');
     $user = (int) $GLOBALS['app']->Session->GetAttribute('user');
     $verified_nodes = $model->CheckNotes($id_set, $user);
     if (Jaws_Error::IsError($verified_nodes)) {
         return $GLOBALS['app']->Session->GetResponse(_t('NOTEPAD_ERROR_NOTE_DELETE'), RESPONSE_ERROR);
     }
     // No notes was verified
     if (empty($verified_nodes)) {
         return $GLOBALS['app']->Session->GetResponse(_t('NOTEPAD_ERROR_NO_PERMISSION'), RESPONSE_ERROR);
     }
     // Delete notes
     $res = $model->Delete($verified_nodes);
     if (Jaws_Error::IsError($res)) {
         return $GLOBALS['app']->Session->GetResponse(_t('NOTEPAD_ERROR_NOTE_DELETE'), RESPONSE_ERROR);
     }
     if (count($id_set) !== count($verified_nodes)) {
         $msg = _t('NOTEPAD_WARNING_DELETE_NOTES_FAILED');
         // FIXME: we are creating response twice
         $GLOBALS['app']->Session->PushResponse($msg, 'Notepad.Response', RESPONSE_WARNING);
         return $GLOBALS['app']->Session->GetResponse($msg, RESPONSE_WARNING);
     }
     $msg = count($id_set) === 1 ? _t('NOTEPAD_NOTICE_NOTE_DELETED') : _t('NOTEPAD_NOTICE_NOTES_DELETED');
     $GLOBALS['app']->Session->PushResponse($msg, 'Notepad.Response');
     return $GLOBALS['app']->Session->GetResponse($msg);
 }
Example #17
0
 /**
  * Builds UI to display a single note
  *
  * @access  public
  * @return  string  XHTML UI
  */
 function OpenNote()
 {
     $id = (int) jaws()->request->fetch('id', 'get');
     $model = $this->gadget->model->load('Notepad');
     $user = (int) $GLOBALS['app']->Session->GetAttribute('user');
     $note = $model->GetNote($id, $user);
     if (Jaws_Error::IsError($note) || empty($note)) {
         return;
     }
     $this->AjaxMe('site_script.js');
     $tpl = $this->gadget->template->load('Open.html');
     $tpl->SetBlock('note');
     $tpl->SetVariable('id', $id);
     $tpl->SetVariable('note_title', $note['title']);
     $tpl->SetVariable('note_content', $this->gadget->ParseText($note['content'], 'Notepad'));
     // Actions
     if ($note['user'] == $user) {
         $tpl->SetBlock('note/actions');
         $tpl->SetVariable('lbl_edit', _t('GLOBAL_EDIT'));
         $tpl->SetVariable('lbl_share', _t('NOTEPAD_SHARE'));
         $tpl->SetVariable('lbl_delete', _t('GLOBAL_DELETE'));
         $tpl->SetVariable('confirmDelete', _t('NOTEPAD_WARNING_DELETE_NOTE'));
         $tpl->SetVariable('notepad_url', $this->gadget->urlMap('Notepad'));
         $tpl->SetVariable('url_edit', $this->gadget->urlMap('EditNote', array('id' => $id)));
         $tpl->SetVariable('url_share', $this->gadget->urlMap('ShareNote', array('id' => $id)));
         $tpl->ParseBlock('note/actions');
     }
     $tpl->ParseBlock('note');
     return $tpl->Get();
 }
Example #18
0
 /**
  * Returns an array with all available items the Menu gadget 
  * can use
  *
  * @access  public
  * @return  array   URLs array
  */
 function Execute()
 {
     $items = array();
     $items[] = array('url' => $this->gadget->urlMap('DefaultAction'), 'title' => $this->gadget->title);
     $items[] = array('url' => $this->gadget->urlMap('Archive'), 'title' => _t('BLOG_ARCHIVE'));
     $items[] = array('url' => $this->gadget->urlMap('CategoriesList'), 'title' => _t('BLOG_ACTIONS_CATEGORIESLIST'), 'title2' => _t('BLOG_CATEGORIES'));
     $items[] = array('url' => $this->gadget->urlMap('PopularPosts'), 'title' => _t('BLOG_POPULAR_POSTS'));
     $items[] = array('url' => $this->gadget->urlMap('PostsAuthors'), 'title' => _t('BLOG_POSTS_AUTHORS'));
     //Blog model
     $pModel = $this->gadget->model->load('Posts');
     $cModel = $this->gadget->model->load('Categories');
     $categories = $cModel->GetCategories();
     if (!Jaws_Error::IsError($categories)) {
         $max_size = 32;
         foreach ($categories as $cat) {
             $url = $this->gadget->urlMap('ShowCategory', array('id' => empty($cat['fast_url']) ? $cat['id'] : $cat['fast_url']));
             $items[] = array('url' => $url, 'title' => Jaws_UTF8::strlen($cat['name']) > $max_size ? Jaws_UTF8::substr($cat['name'], 0, $max_size) . '...' : $cat['name'], 'acl_key' => 'CategoryAccess', 'acl_subkey' => $cat['id']);
         }
     }
     $entries = $pModel->GetEntries('');
     if (!Jaws_Error::IsError($entries)) {
         $max_size = 32;
         foreach ($entries as $entry) {
             $url = $this->gadget->urlMap('SingleView', array('id' => empty($entry['fast_url']) ? $entry['id'] : $entry['fast_url']));
             $items[] = array('url' => $url, 'title' => Jaws_UTF8::strlen($entry['title']) > $max_size ? Jaws_UTF8::substr($entry['title'], 0, $max_size) . '...' : $entry['title']);
         }
     }
     return $items;
 }
Example #19
0
 /**
  * Displays the emblems
  *
  * @access  public
  * @return  string   XHTML UI
  */
 function Display()
 {
     $tpl = $this->gadget->template->load('Emblems.html');
     $tpl->SetBlock('emblems');
     $tpl->SetVariable('title', _t('EMBLEMS_ACTION_TITLE'));
     $model = $this->gadget->model->load('Emblems');
     $emblems = $model->GetEmblems(true);
     if (!Jaws_Error::IsError($emblems)) {
         $site = urlencode(Jaws_Utils::getBaseURL('/', false));
         $page = urlencode(Jaws_Utils::getRequestURL(false));
         $name = urlencode($this->gadget->registry->fetch('site_name', 'Settings'));
         $slogan = urlencode($this->gadget->registry->fetch('site_slogan', 'Settings'));
         $title = $GLOBALS['app']->Layout->GetTitle();
         foreach ($emblems as $e) {
             $e['url'] = str_replace(array('{url}', '{base_url}', '{requested_url}', '{site_name}', '{site_slogan}', '{title}'), array($page, $site, $page, $name, $slogan, $title), $e['url']);
             $tpl->SetBlock('emblems/emblem');
             $tpl->SetVariable('id', $e['id']);
             $tpl->SetVariable('title', _t('EMBLEMS_TYPE_' . $e['type'], $e['title']));
             $tpl->SetVariable('image', $GLOBALS['app']->getDataURL('emblems/' . $e['image']));
             $tpl->SetVariable('url', $e['url']);
             $tpl->ParseBlock('emblems/emblem');
         }
     }
     $tpl->ParseBlock('emblems');
     return $tpl->Get();
 }
Example #20
0
 /**
  * Returns an array with the results of a tag content
  *
  * @access  public
  * @param   string  $action     Action name
  * @param   array   $references Array of References
  * @return  array   An array of entries that matches a certain pattern
  */
 function Execute($action, $references)
 {
     if (empty($action) || !is_array($references) || empty($references)) {
         return false;
     }
     $table = Jaws_ORM::getInstance()->table('linkdump_links');
     $table->select('id:integer', 'title', 'description', 'updatetime');
     $result = $table->where('id', $references, 'in')->fetchAll();
     if (Jaws_Error::IsError($result)) {
         return array();
     }
     $date = Jaws_Date::getInstance();
     $links = array();
     foreach ($result as $r) {
         $link = array();
         $link['title'] = $r['title'];
         $link['url'] = $this->gadget->urlMap('Link', array('id' => $r['id']));
         $link['outer'] = true;
         $link['image'] = 'gadgets/LinkDump/Resources/images/logo.png';
         $link['snippet'] = $r['description'];
         $link['date'] = $date->ToISO($r['updatetime']);
         $links[$r['id']] = $link;
     }
     return $links;
 }
Example #21
0
 /**
  * Returns a list of  forums at a request level
  *
  * @access  public
  * @param   int     $gid                Group ID
  * @param   bool    $onlyPublished
  * @param   bool    $last_topic_detail
  * @return  mixed   Array with all the available forums or Jaws_Error on error
  */
 function GetForums($gid = false, $onlyAccessible = true, $onlyPublished = false, $last_topic_detail = false)
 {
     $table = Jaws_ORM::getInstance()->table('forums');
     if ($last_topic_detail) {
         $table->select('forums.id:integer', 'forums.title', 'forums.description', 'forums.fast_url', 'topics:integer', 'posts:integer', 'last_topic_id:integer', 'forums_topics.last_post_time', 'forums_topics.replies:integer', 'users.username', 'users.nickname', 'forums.locked:boolean', 'forums.published:boolean');
         $table->join('forums_topics', 'forums.last_topic_id', 'forums_topics.id', 'left');
         $table->join('users', 'forums_topics.last_post_uid', 'users.id', 'left');
     } else {
         $table->select('id:integer', 'title', 'description', 'fast_url', 'topics:integer', 'posts:integer', 'locked:boolean', 'published:boolean', 'gid:integer');
     }
     if (!empty($gid)) {
         $table->and()->where('gid', $gid);
     }
     if ($onlyPublished) {
         $table->and()->where('forums.published', true);
     }
     $result = $table->orderBy('forums.order asc')->fetchAll();
     if (Jaws_Error::isError($result)) {
         return array();
     }
     $forums = array();
     foreach ($result as $forum) {
         if ($this->gadget->GetPermission('ForumPublic', $forum['id'])) {
             $forums[] = $forum;
         }
     }
     return $forums;
 }
Example #22
0
 /**
  * Displays a list of blog categories with a link to each one's posts and xml feeds
  *
  * @access  public
  * @return  string  XHTML template content
  */
 function CategoriesList()
 {
     $tpl = $this->gadget->template->load('Categories.html');
     $tpl->SetBlock('categories_list');
     $tpl->SetVariable('title', _t('BLOG_CATEGORIES'));
     $pModel = $this->gadget->model->load('Posts');
     $entries = $pModel->GetEntriesAsCategories();
     if (!Jaws_Error::IsError($entries)) {
         $cModel = $this->gadget->model->load('Categories');
         $howmany = $cModel->GetCategoryNumberOfPages(0);
         if (!empty($howmany)) {
             $entries[] = array('id' => 0, 'name' => _t('BLOG_UNCATEGORIZED'), 'fast_url' => '', 'howmany' => $howmany);
         }
         foreach ($entries as $e) {
             $tpl->SetBlock('categories_list/item');
             $tpl->SetVariable('category', $e['name']);
             $cid = empty($e['fast_url']) ? $e['id'] : $e['fast_url'];
             $tpl->SetVariable('url', $this->gadget->urlMap('ShowCategory', array('id' => $cid)));
             $tpl->SetVariable('rssfeed', $this->gadget->urlMap('ShowRSSCategory', array('id' => $cid)));
             $tpl->SetVariable('atomfeed', $this->gadget->urlMap('ShowAtomCategory', array('id' => $cid)));
             $tpl->SetVariable('howmany', $e['howmany']);
             // display subscription if installed
             if (Jaws_Gadget::IsGadgetInstalled('Subscription')) {
                 $sHTML = Jaws_Gadget::getInstance('Subscription')->action->load('Subscription');
                 $tpl->SetVariable('subscription', $sHTML->ShowSubscription('Blog', 'Category', $e['id']));
             }
             $tpl->ParseBlock('categories_list/item');
         }
     }
     $tpl->ParseBlock('categories_list');
     return $tpl->Get();
 }
Example #23
0
 /**
  * Returns an array with the results of a search
  *
  * @access  public
  * @param   string  $pSql   Prepared search(WHERE) SQL
  * @return  array   An array of entries that matches a certain pattern
  */
 function Execute($pSql = '')
 {
     $params = array();
     $sql = '
         SELECT
            [id],[name], [title], [description], [meta_keywords], [meta_description]
         FROM [[tags]]
         ';
     if ($GLOBALS['app']->Session->Logged()) {
         $params['user'] = $GLOBALS['app']->Session->GetAttribute('user');
         $wStr = '([user]=0 OR [user]={user})';
     } else {
         $wStr = '[user]=0';
     }
     $sql .= ' WHERE ' . $wStr;
     $sql .= ' AND ' . $pSql;
     $sql .= ' ORDER BY [id] desc';
     $types = array('integer', 'text', 'text', 'text', 'text', 'text');
     $result = Jaws_DB::getInstance()->queryAll($sql, $params, $types);
     if (Jaws_Error::IsError($result)) {
         return array();
     }
     $tags = array();
     foreach ($result as $t) {
         $tag = array();
         $tag['title'] = $t['title'];
         $url = $this->gadget->urlMap('ViewTag', array('tag' => $t['name']));
         $tag['url'] = $url;
         $tag['image'] = 'gadgets/Tags/Resources/images/logo.png';
         $tag['snippet'] = $t['description'];
         $tag['date'] = null;
         $tags[$t['id']] = $tag;
     }
     return $tags;
 }
Example #24
0
 /**
  * Shows existing trackbacks for a given entry
  *
  * @access  public
  * @param   int     $id     entry id
  * @return  string  XHTML template content
  */
 function ShowTrackbacks($id)
 {
     if ($this->gadget->registry->fetch('trackback') == 'true') {
         $model = $this->gadget->model->load('Trackbacks');
         $trackbacks = $model->GetTrackbacks($id);
         $tpl = $this->gadget->template->load('Trackbacks.html');
         $tpl->SetBlock('trackbacks');
         $tburi = $this->gadget->urlMap('Trackback', array('id' => $id), true);
         $tpl->SetVariable('TrackbackURI', $tburi);
         if (!Jaws_Error::IsError($trackbacks)) {
             $date = Jaws_Date::getInstance();
             foreach ($trackbacks as $tb) {
                 $tpl->SetBlock('trackbacks/item');
                 $tpl->SetVariablesArray($tb);
                 $tpl->SetVariable('createtime-iso', $tb['createtime']);
                 $tpl->SetVariable('createtime', $date->Format($tb['createtime']));
                 $tpl->SetVariable('createtime-monthname', $date->Format($tb['createtime'], 'MN'));
                 $tpl->SetVariable('createtime-monthabbr', $date->Format($tb['createtime'], 'M'));
                 $tpl->SetVariable('createtime-month', $date->Format($tb['createtime'], 'm'));
                 $tpl->SetVariable('createtime-dayname', $date->Format($tb['createtime'], 'DN'));
                 $tpl->SetVariable('createtime-dayabbr', $date->Format($tb['createtime'], 'D'));
                 $tpl->SetVariable('createtime-day', $date->Format($tb['createtime'], 'd'));
                 $tpl->SetVariable('createtime-year', $date->Format($tb['createtime'], 'Y'));
                 $tpl->SetVariable('createtime-time', $date->Format($tb['createtime'], 'g:ia'));
                 $tpl->ParseBlock('trackbacks/item');
             }
         }
         $tpl->ParseBlock('trackbacks');
         return $tpl->Get();
     }
 }
Example #25
0
File: Group.php Project: uda/jaws
 /**
  * Prepares the data (an array) of polls
  *
  * @access  public
  * @param   int     $offset  Offset of data
  * @return  array   Data array
  */
 function GetPollGroups($offset = null)
 {
     $model = $this->gadget->model->load('Group');
     $groups = $model->GetPollGroups(10, $offset);
     if (Jaws_Error::IsError($groups)) {
         return array();
     }
     $newData = array();
     foreach ($groups as $group) {
         $groupData = array();
         $groupData['title'] = $group['title'];
         if ($group['published'] == true) {
             $groupData['published'] = _t('GLOBAL_YES');
         } else {
             $groupData['published'] = _t('GLOBAL_NO');
         }
         $actions = '';
         if ($this->gadget->GetPermission('ManageGroups')) {
             $link =& Piwi::CreateWidget('Link', _t('GLOBAL_EDIT'), "javascript:editPollGroup(this, '" . $group['id'] . "');", STOCK_EDIT);
             $actions .= $link->Get() . '&nbsp;';
             $link =& Piwi::CreateWidget('Link', _t('POLL_GROUPS_POLLS_TITLE'), "javascript:editPollGroupPolls(this, '" . $group['id'] . "');", 'gadgets/Poll/Resources/images/polls_mini.png');
             $actions .= $link->Get() . '&nbsp;';
             $link =& Piwi::CreateWidget('Link', _t('GLOBAL_DELETE'), "javascript:deletePollGroup(this, '" . $group['id'] . "');", STOCK_DELETE);
             $actions .= $link->Get() . '&nbsp;';
         }
         $groupData['actions'] = $actions;
         $newData[] = $groupData;
     }
     return $newData;
 }
Example #26
0
 /**
  * Sends email to user
  *
  * @access  public
  * @param   string  $name       Name
  * @param   string  $email      Email address
  * @param   string  $company
  * @param   string  $url
  * @param   string  $tel
  * @param   string  $fax
  * @param   string  $mobile
  * @param   string  $address
  * @param   string  $rcipient   Rcipient ID
  * @param   string  $subject    Subject of message
  * @param   string  $attachment Attachment filename
  * @param   string  $message    Message content
  * @return  bool    True on Success or False on Failure
  */
 function InsertContact($name, $email, $company, $url, $tel, $fax, $mobile, $address, $recipient, $subject, $attachment, $message)
 {
     $now = Jaws_DB::getInstance()->date();
     $data = array();
     $data['[user]'] = $GLOBALS['app']->Session->GetAttribute('user');
     $data['ip'] = $_SERVER['REMOTE_ADDR'];
     $data['name'] = $name;
     $data['email'] = $email;
     $data['company'] = $company;
     $data['url'] = $url;
     $data['tel'] = $tel;
     $data['fax'] = $fax;
     $data['mobile'] = $mobile;
     $data['address'] = $address;
     $data['recipient'] = (int) $recipient;
     $data['subject'] = $subject;
     $data['attachment'] = $attachment;
     $data['msg_txt'] = $message;
     $data['reply'] = '';
     $data['reply_sent'] = 0;
     $data['createtime'] = $now;
     $data['updatetime'] = $now;
     $cntctTable = Jaws_ORM::getInstance()->table('contacts');
     $result = $cntctTable->insert($data)->exec();
     if (Jaws_Error::IsError($result)) {
         return false;
     }
     $GLOBALS['app']->Session->SetCookie('visitor_name', $name, 60 * 24 * 150);
     $GLOBALS['app']->Session->SetCookie('visitor_email', $email, 60 * 24 * 150);
     $GLOBALS['app']->Session->SetCookie('visitor_url', $url, 60 * 24 * 150);
     return $result;
 }
Example #27
0
File: Tags.php Project: uda/jaws
 /**
  * Fetches files having specific tag
  *
  * @access  public
  * @param   string  $action     Action name
  * @param   array   $references Array of References
  * @return  array   An array of entries that matches a certain pattern
  */
 function Execute($action, $references)
 {
     if (empty($action) || !is_array($references) || empty($references)) {
         return false;
     }
     $table = Jaws_ORM::getInstance()->table('directory');
     $table->select('id:integer', 'title', 'description', 'update_time');
     $result = $table->where('hidden', false)->and()->where('id', $references, 'in')->fetchAll();
     if (Jaws_Error::IsError($result)) {
         return array();
     }
     $date = Jaws_Date::getInstance();
     $files = array();
     foreach ($result as $r) {
         $file = array();
         $file['title'] = $r['title'];
         $file['url'] = $this->gadget->urlMap('Directory', array('id' => $r['id']));
         $file['outer'] = false;
         $file['image'] = 'gadgets/Directory/Resources/images/logo.png';
         $file['snippet'] = $r['description'];
         $file['date'] = $date->ToISO($r['update_time']);
         $files[$r['id']] = $file;
     }
     return $files;
 }
Example #28
0
 /**
  * Returns an array with the results of a tag content
  *
  * @access  public
  * @param   string  $action     Action name
  * @param   array   $references Array of References
  * @return  array   An array of entries that matches a certain pattern
  */
 function Execute($action, $references)
 {
     if (empty($action) || !is_array($references) || empty($references)) {
         return false;
     }
     $table = Jaws_ORM::getInstance()->table('blog');
     $table->select('id:integer', 'fast_url', 'title', 'summary', 'text', 'updatetime');
     $result = $table->where('id', $references, 'in')->fetchAll();
     if (Jaws_Error::IsError($result)) {
         return array();
     }
     $date = Jaws_Date::getInstance();
     $posts = array();
     foreach ($result as $r) {
         $post = array();
         $post['title'] = $r['title'];
         $post['url'] = $this->gadget->urlMap('SingleView', array('id' => $r['fast_url']));
         $post['outer'] = false;
         $post['image'] = 'gadgets/Blog/Resources/images/logo.png';
         $post['snippet'] = $r['summary'];
         $post['date'] = $date->ToISO($r['updatetime']);
         $posts[$r['id']] = $post;
     }
     return $posts;
 }
Example #29
0
 /**
  * Updates users of a event
  *
  * @access  public
  * @param   int     $id     Event ID
  * @param   array   $users  Set of User IDs
  * @return  mixed   True or Jaws_Error
  */
 function UpdateEventUsers($id, $users)
 {
     // Update shared status of the event
     $shared = !empty($users);
     $table = Jaws_ORM::getInstance()->table('ec_events');
     $table->beginTransaction();
     $table->update(array('shared' => $shared));
     $res = $table->where('id', $id)->exec();
     if (Jaws_Error::IsError($res)) {
         return $res;
     }
     // Delete current users except owner
     $uid = (int) $GLOBALS['app']->Session->GetAttribute('user');
     $table = Jaws_ORM::getInstance()->table('ec_users');
     $table->delete()->where('event', $id)->and();
     $res = $table->where('user', $uid, '<>')->exec();
     if (Jaws_Error::IsError($res)) {
         return $res;
     }
     // Insert users
     if (!empty($users)) {
         foreach ($users as &$user) {
             $user = array('event' => $id, 'user' => $user, 'owner' => $uid);
         }
         $table = Jaws_ORM::getInstance()->table('ec_users');
         $table->reset();
         $table->insertAll(array('event', 'user', 'owner'), $users);
         $res = $table->exec();
         if (Jaws_Error::IsError($res)) {
             return $res;
         }
     }
     $table->commit();
 }
Example #30
0
 /**
  * Displays the captcha image
  *
  * @access  public
  */
 function image($key)
 {
     $value = $this->randomEquation();
     $result = $this->update($key, $value[1]);
     if (Jaws_Error::IsError($result)) {
         $value = '';
     } else {
         $value = $value[0];
     }
     $value .= '=?';
     $bg = dirname(__FILE__) . '/resources/math.bg.png';
     $im = imagecreatefrompng($bg);
     imagecolortransparent($im, imagecolorallocate($im, 255, 255, 255));
     $font = dirname(__FILE__) . '/resources/comicbd.ttf';
     $grey = imagecolorallocate($im, 0x7f, 0x7f, 0x7f);
     // shadow
     imagettftext($im, 18, 0, 8, 22, $grey, $font, $value);
     // text
     imagettftext($im, 18, 0, 12, 24, $grey, $font, $value);
     header('Content-Type: image/png');
     ob_start();
     imagepng($im);
     $content = ob_get_contents();
     ob_end_clean();
     imagedestroy($im);
     return $content;
 }