public function display($tpl = null) { $this->state = $this->get('State'); $this->items = $this->get('Items'); $this->pagination = $this->get('Pagination'); // Get the ID of users which do not have records in Identity Proof table "users". $newUsers = array(); foreach ($this->items as $item) { if (!$item->user_id) { $newUsers[] = $item->id; } } // Create users if they do not exist. if (!empty($newUsers)) { $model = $this->getModel(); $model->createUsers($newUsers); } // Add submenu IdentityProofHelper::addSubmenu($this->getName()); // Prepare sorting data $this->prepareSorting(); // Prepare actions $this->addToolbar(); $this->addSidebar(); $this->setDocument(); parent::display($tpl); }
public function display($tpl = null) { $this->state = $this->get('State'); $this->items = $this->get('Items'); $this->pagination = $this->get('Pagination'); // Add submenu IdentityProofHelper::addSubmenu($this->getName()); // Prepare sorting data $this->prepareSorting(); // Prepare actions $this->addToolbar(); $this->addSidebar(); $this->setDocument(); parent::display($tpl); }
public function download() { // Check for request forgeries. JSession::checkToken("post") or jexit(JText::_('JINVALID_TOKEN')); $fileId = $this->input->post->get("file_id", 0, "int"); $userId = JFactory::getUser()->get("id"); // Validate the user. if (!$userId) { $this->setRedirect(JRoute::_('index.php?option=com_identityproof&view=dashboard', false), JText::_('COM_IDENTITYPROOF_ERROR_SYSTEM')); return; } $params = JComponentHelper::getParams("com_identityproof"); /** @var $params Joomla\Registry\Registry */ try { // Load file data. jimport("identityproof.file"); $file = new IdentityProofFile(JFactory::getDbo()); $file->load($fileId); // Prepare keys. $keys = array("private" => $file->getPrivate(), "public" => $file->getPublic()); // Prepare meta data $fileSize = $file->getMetaData("filesize"); $mimeType = $file->getMetaData("mime_type"); // Decrypt the file. $filePath = JPath::clean($params->get("files_path") . DIRECTORY_SEPARATOR . $file->getFilename()); $output = file_get_contents($filePath); $output = IdentityProofHelper::decrypt($keys, $output); } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_IDENTITYPROOF_ERROR_SYSTEM')); } $app = JFactory::getApplication(); $app->setHeader('Content-Type', $mimeType, true); $app->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true); $app->setHeader('Content-Transfer-Encoding', 'binary', true); $app->setHeader('Pragma', 'no-cache', true); $app->setHeader('Expires', '0', true); $app->setHeader('Content-Disposition', 'attachment; filename=' . $file->getFilename(), true); $app->setHeader('Content-Length', $fileSize, true); $doc = JFactory::getDocument(); $doc->setMimeEncoding($mimeType); $app->sendHeaders(); echo $output; $app->close(); }
public function display($tpl = null) { $this->version = new IdentityProofVersion(); // Load ITPrism library version jimport("itprism.version"); if (!class_exists("ITPrismVersion")) { $this->itprismVersion = JText::_("COM_IDENTITYPROOF_ITPRISM_LIBRARY_DOWNLOAD"); } else { $itprismVersion = new ITPrismVersion(); $this->itprismVersion = $itprismVersion->getShortVersion(); } // Get URI $this->uri = JUri::getInstance(); $uriCloned = clone $this->uri; // Generate HTTPS URI. $uriCloned->setScheme("https"); $this->uriHTTPS = $uriCloned->toString(); // Add submenu IdentityProofHelper::addSubmenu($this->getName()); $this->addToolbar(); $this->addSidebar(); $this->setDocument(); parent::display($tpl); }
/** * Save data in the database. * * @param array $data The data of item * * @throws Exception * @return int Item ID */ public function save($data) { $title = JArrayHelper::getValue($data, "title"); $file = JArrayHelper::getValue($data, "file"); $filename = basename($file); $userId = JFactory::getUser()->get("id"); if (!JFile::exists($file)) { throw new Exception(JText::_('COM_IDENTITYPROOF_ERROR_FILE_CANT_BE_UPLOADED')); } // Load the data from the file. $fileData = file_get_contents($file); if (!empty($fileData)) { $keysData = $this->generateKeys(); // Get mime type and file size. $fileInfo = new finfo(FILEINFO_MIME_TYPE); $metaData = array("filesize" => filesize($file), "mime_type" => $fileInfo->file($file)); $fileData = IdentityProofHelper::encrypt($keysData, $fileData); $params = JComponentHelper::getParams("com_identityproof"); $destination = JPath::clean($params->get("files_path") . DIRECTORY_SEPARATOR . $filename); file_put_contents($destination, $fileData); JFile::delete($file); } else { $metaData = null; $keysData = array(); } // Unset the file data and clean the memory. $fileData = null; // Encode the options. if (!empty($metaData)) { $metaData = json_encode($metaData); } // Remove the file. JFile::delete($file); // Load a record from the database $row = $this->getTable(); $row->set("title", $title); $row->set("filename", $filename); $row->set("private", !isset($keysData["private"]) ? null : $keysData["private"]); $row->set("public", !isset($keysData["public"]) ? null : $keysData["public"]); $row->set("meta_data", $metaData); $row->set("user_id", $userId); $row->store(true); return $row->get("id"); }