Example #1
0
 public function __construct($config = array())
 {
     $udbPath = UserNotesHelper::userDataPath() . '/usernotes.db3';
     $db = JDatabaseDriver::getInstance(array('driver' => 'sqlite', 'database' => $udbPath));
     $config['dbo'] = $db;
     parent::__construct($config);
 }
 public function begin()
 {
     if (!$this->uid) {
         return;
     }
     $htm = '<!DOCTYPE html><title></title>';
     $udp = UserNotesHelper::userDataPath();
     mkdir($udp . '/attach', 0777, true);
     file_put_contents($udp . '/index.html', $htm);
     file_put_contents($udp . '/attach/index.html', $htm);
     $this->setRedirect(JRoute::_('index.php?option=com_usernotes', false));
 }
 public function __construct($config = array())
 {
     $this->_storPath = UserNotesHelper::userDataPath();
     $udbPath = $this->_storPath . '/usernotes.db3';
     $doInit = !file_exists($udbPath);
     $option = array('driver' => 'sqlite', 'database' => $udbPath);
     $db = JDatabaseDriver::getInstance($option);
     $db->connect();
     $db->getConnection()->sqliteCreateFunction('b64d', 'base64_decode', 1);
     if ($doInit) {
         require_once JPATH_COMPONENT . '/helpers/db.php';
         UserNotesHelperDb::buildDb($db);
     }
     $config['dbo'] = $db;
     parent::__construct($config);
 }
 public function display($tpl = null)
 {
     $app = JFactory::getApplication();
     // Get view related request variables.
     $this->down = $app->input->get('down', 0, 'int');
     $cat = explode('|', $app->input->getString('cat'), 2);
     $this->fnam = $cat[1];
     // Get path to file
     $udp = UserNotesHelper::userDataPath();
     $this->fpath = JPATH_BASE . '/' . $udp . '/attach/' . $cat[0] . '/' . $cat[1];
     // Get file mime type
     if (file_exists($this->fpath)) {
         $finfo = finfo_open(FILEINFO_MIME_TYPE);
         $this->mime = finfo_file($finfo, $this->fpath);
     }
     return parent::display($tpl);
 }
 public function add_attached($contentID = 0, $files = NULL, $notesid = null)
 {
     if (!$contentID || !$files) {
         return;
     }
     $path = JPATH_BASE . '/' . UserNotesHelper::userDataPath() . '/attach/' . $contentID;
     $msg = '';
     $fns = array();
     foreach ($files as $file) {
         if ($file['error'] == UPLOAD_ERR_OK) {
             $tmp_name = $file['tmp_name'];
             if (is_uploaded_file($tmp_name)) {
                 @mkdir($path);
                 $name = $file['name'];
                 move_uploaded_file($tmp_name, $path . '/' . $name);
                 $fns[] = $name;
             } else {
                 $msg .= 'failed to upload';
             }
         } elseif ($file['error'] != UPLOAD_ERR_NO_FILE) {
             $msg .= "Error: {$file['error']}";
         }
     }
     if ($fns) {
         try {
             $db = $this->getDbo();
             foreach ($fns as $fn) {
                 $fsz = filesize($path . '/' . $fn);
                 $db->setQuery('SELECT attached FROM fileatt WHERE contentID=' . $contentID . ' AND attached=' . $db->quote($fn));
                 $r = $db->loadResult();
                 if ($r) {
                     $db->setQuery('UPDATE fileatt SET fsize=' . $fsz . ' WHERE contentID=' . $contentID . ' AND attached=' . $db->quote($fn));
                     $db->execute();
                 } else {
                     $db->setQuery('INSERT INTO fileatt (contentID,fsize,attached) VALUES (' . $contentID . ',' . $fsz . ',' . $db->quote($fn) . ')');
                     $db->execute();
                 }
             }
         } catch (Exception $e) {
             $this->setError($e);
         }
     }
     if ($msg) {
         var_dump($contentID, $msg);
     }
 }