/** * Index action */ function indexAction() { $filepath = CACHE_DIR . '/analytics/report-' . Fox_Core_Model_Date::getCurrentDate('Y-m-d') . '.xml'; $xDom = new Uni_Data_XDOMDocument(); $xDom->load($filepath); header('Content-Type: text/xml'); echo $xDom->saveXML(); }
/** * Send newsletter to subscribers */ public function sendNewsletter() { $subscriberModel = Fox::getModel('newsletter/subscriber'); $subscriberCollection = $subscriberModel->getCollection('status=' . Fox_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED); $currDate = Fox_Core_Model_Date::getCurrentDate('Y-m-d H:i:s'); $modelTemplate = Fox::getModel('core/email/template'); foreach ($subscriberCollection as $subscriber) { $subject = $modelTemplate->getParsedContent($this->getSubject(), array('email' => $subscriber['email'], 'name' => $subscriber['name'])); $message = $modelTemplate->getParsedContent($this->getContent(), array('email' => $subscriber['email'], 'name' => $subscriber['name'])); $modelTemplate->sendMail($subscriber['email'], $this->getSenderEmail(), $this->getSenderName(), $subject, $message); } $this->setStatus(Fox_Newsletter_Model_Template::STATUS_SENT); $this->setLastSent($currDate); $this->save(); }
/** * Render contents * * @return string * @throws Exception if arguments passed is less than two */ public function render() { if (func_num_args() < 2) { throw new Exception('Too few parameters! Two required.'); } $args = func_get_args(); $item = $args[0]; $column = $args[1]; $value = $item->{$column['fieldMethod']}(); if ($column['type'] == self::TYPE_OPTIONS) { $colMarkup = $column['options'][$value]; } else { if ($column['type'] == self::TYPE_DATE) { $colMarkup = $value != NULL && $value != '0000-00-00' && $value != '0000-00-00 00:00:00' ? Fox_Core_Model_Date::__toLocaleDate(strtotime($value), isset($column['format']) ? $column['format'] : 'Y-m-d', isset($column['locale']) ? $column['locale'] : NULL) : (isset($column['default']) ? $column['default'] : ''); } else { $colMarkup = $value; } } return $colMarkup; }
/** * Index action */ public function indexAction() { if ($this->getRequest()->isPost()) { try { $data = $this->getRequest()->getPost(); $model = Fox::getModel('contact/contact'); $data['status'] = Fox_Contact_Model_Contact::STATUS_UNREAD; $data['contact_date'] = Fox_Core_Model_Date::getCurrentDate('Y-m-d H:i:s'); $model->setData($data); $model->save(); try { Fox::getHelper('core/message')->setInfo("Your request was successfully sent."); $modelTemplate = Fox::getModel('core/email/template'); $modelTemplate->sendTemplateMail(Fox::getPreference('contact/receiver/email_template'), Fox::getPreference('contact/receiver/email'), array('sender_name' => $data['name'], 'sender_email' => $data['email']), $data); } catch (Exception $e) { } } catch (Exception $e) { Fox::getHelper('core/message')->setError($e->getMessage()); } } $this->loadLayout(); $this->renderLayout(); }
/** * Save action */ public function saveAction() { if ($this->getRequest()->isPost()) { $data = $this->getRequest()->getPost(); try { $model = Fox::getModel('core/email/template'); $curDate = Fox_Core_Model_Date::getCurrentDate('Y-m-d H:i:s'); if ($id = $this->getRequest()->getParam('id')) { $model->load($id); } else { $data['created_date'] = $curDate; } $data['modified_date'] = $curDate; $model->setData($data); $model->save(); Fox::getHelper('core/message')->setInfo('"' . $model->getName() . '" was successfully saved.'); if ($this->getRequest()->getParam('back')) { $this->sendRedirect('*/*/edit', array('id' => $model->getId())); return; } } catch (Exception $e) { Fox::getModel('core/session')->setFormData($data); Fox::getHelper('core/message')->addError($e->getMessage()); $this->sendRedirect('*/*/edit', array('id' => $this->getRequest()->getParam('id'))); return; } } $this->sendRedirect('*/*/'); }
/** * Create new member * * @param array $data * @return Fox_Member_Model_Member */ public function createMember($data) { $code = NULL; $password = $data['password']; $confirmPassword = $data['confirm_password']; if ($password != $confirmPassword) { throw new Exception('Password must match confirm password.'); } $setModel = Fox::getModel('eav/set'); $setDetail = $setModel->getAttributeSetByEntity($this->getEavEntityType()); if (!$setDetail) { throw new Exception('Attribute set was not found.'); } $this->unsetData(); $this->getAdapter()->beginTransaction(); try { $this->setData($data); $this->setAttributeSetId($setDetail['id']); $this->setPassword(md5($password)); $this->setFirstName(ucwords($data['first_name'])); $this->setLastName(ucwords($data['last_name'])); $curDate = Fox_Core_Model_Date::getCurrentDate('Y-m-d H:i:s'); $this->setJoinDate($curDate); $isConfirmationRequired = Fox::getPreference('member/account/required_email_confirmation'); if ($isConfirmationRequired) { $this->setStatus(Fox_Member_Model_Status::STATUS_NOT_CONFIRM); } else { $this->setStatus(Fox_Member_Model_Status::STATUS_ACTIVE); } $this->save(); $this->getAdapter()->commit(); } catch (Exception $e) { $this->getAdapter()->rollBack(); throw new Exception($e->getMessage()); } $vars['name'] = $this->getFirstName(); $vars['email'] = $this->getEmailId(); $vars['password'] = $password; $this->sendWelcomeMail($vars); if ($isConfirmationRequired) { $code = strtolower(substr(md5(time() * mt_rand()), 0, 20)); $verificationModel = Fox::getModel('member/verification'); $verificationModel->load($this->getId(), 'mem_id'); $verificationModel->setMemId($this->getId()); $verificationModel->setVerificationCode($code); $verificationModel->save(); $vars['link'] = Fox::getUrl('member/account/verification', array('id' => $this->getId(), 'code' => $code)); $this->sendConfirmationLinkMail($vars); } return $this; }
/** * Get news collection * * @return Uni_Core_Model_Collection */ function getNews() { $currentDate = Fox_Core_Model_Date::getCurrentDate('Y-m-d'); return Fox::getModel('news/news')->getCollection('status=' . Fox_News_Model_News::STATUS_ENABLED . " AND (('" . $currentDate . "' BETWEEN date_from AND date_to) OR (date_to>='" . $currentDate . "' AND date_from='0000-00-00') OR (date_from<='" . $currentDate . "' AND date_to='0000-00-00') OR (ISNULL(date_to) AND ISNULL(date_from)) OR (date_to='0000-00-00' AND date_from='0000-00-00'))", '*', 'sort_order'); }
/** * Create database backup file */ public function createBackup() { $this->getAdapter()->beginTransaction(); try { $this->setFileName('DB_' . time() . '.' . self::FILE_EXTENSION . '.' . self::BACKUP_EXTENSION); $this->openStream(); $this->write($this->getHeader()); $tables = $this->getTables(); $limit = 1; foreach ($tables as $table) { $this->write($this->getTableHeader($table) . $this->getTableDropSql($table) . "\n"); $this->write($this->getTableCreateSql($table, false) . "\n"); $this->write($this->getTableDataBeforeSql($table)); $totalRows = (int) $this->getAdapter()->fetchOne('SELECT COUNT(*) FROM ' . $this->getAdapter()->quoteIdentifier($table)); for ($i = 0; $i < $totalRows; $i++) { $this->write($this->getTableDataSql($table, $limit, $i * $limit)); } $this->write($this->getTableDataAfterSql($table)); } $this->write($this->getTableForeignKeysSql()); $this->write($this->getFooter()); $this->closeStream(); $this->setFileSize($this->getBackupSize()); $this->setBackupDate(Fox_Core_Model_Date::getCurrentDate('Y-m-d H:i:s')); $this->save(); $this->getAdapter()->commit(); Fox::getHelper('core/message')->setInfo('Backup was successfully created.'); } catch (Exception $e) { Fox::getHelper('core/message')->setError($e->getMessage()); $this->getAdapter()->rollback(); $this->closeStream(); } }
/** * Forget password action * * Sends an email with link to user which redirects to change password interface */ public function forgetPasswordAction() { if (Fox::getModel('admin/session')->getLoginData()) { $this->sendRedirect('*/dashboard/'); } if ($this->getRequest()->isPost()) { try { $data = $this->getRequest()->getPost(); $model = Fox::getModel('admin/user'); $model->load($data['username'], 'username'); if ($model->getId()) { $code = strtolower(substr(md5(time() * mt_rand()), 0, 20)); $modelSetCode = Fox::getModel('admin/forgetPassword'); $modelSetCode->load($model->getId(), 'user_id'); $modelSetCode->setUserId($model->getId()); $modelSetCode->setCode($code); $modelSetCode->setCreatedOn(Fox_Core_Model_Date::getCurrentDate('Y-m-d H:i:s')); $modelSetCode->save(); Fox::getHelper('core/message')->setInfo('Change Password link has been sent to your email id.'); try { $modelTemplate = Fox::getModel('core/email/template'); $sender = Fox::getPreference('admin/password/forgot_email_sender'); $template = Fox::getPreference('admin/password/forgot_email_template'); $modelTemplate->sendTemplateMail($template, $model->getEmail(), $sender, array('name' => $model->getFirstname(), 'link' => Fox::getUrl('*/*/change-password', array('user_id' => $model->getId(), 'code' => $code)))); } catch (Exception $e) { } $this->sendRedirect('*/*/'); } else { throw new Exception('Invalid username was given.'); } } catch (Exception $e) { Fox::getHelper('core/message')->setError($e->getMessage()); } } $this->loadLayout(); $this->renderLayout(); }
/** * Prepare package xml * * @return bool */ protected function preparePackage() { $pkgXml = $this->getPackageXml(); /* generating package nodes */ $extInfo = Uni_Data_XDOMDocument::createNode(self::PACKAGE_ROOT_ELEMENT, array(), $pkgXml); $name = Uni_Data_XDOMDocument::createNode(self::PACKAGE_NAME_ELEMENT, array(), $pkgXml); $version = Uni_Data_XDOMDocument::createNode(self::PACKAGE_VERSION_ELEMENT, array(), $pkgXml); $description = Uni_Data_XDOMDocument::createNode(self::PACKAGE_DESCRIPTION_ELEMENT, array(), $pkgXml); $summary = Uni_Data_XDOMDocument::createNode(self::PACKAGE_SUMMARY_ELEMENT, array(), $pkgXml); $license = Uni_Data_XDOMDocument::createNode(self::PACKAGE_LICENSE_ELEMENT, array(), $pkgXml); $releaseNote = Uni_Data_XDOMDocument::createNode(self::PACKAGE_RELEASE_NOTE_ELEMENT, array(), $pkgXml); $stability = Uni_Data_XDOMDocument::createNode(self::PACKAGE_STABILITY_ELEMENT, array(), $pkgXml); $date = Uni_Data_XDOMDocument::createNode(self::PACKAGE_DATE_ELEMENT, array(), $pkgXml); $name->appendChild($pkgXml->createTextNode($this->getName())); $version->appendChild($pkgXml->createTextNode($this->getVersion())); $summary->appendChild($pkgXml->createTextNode($this->getSummary())); $description->appendChild($pkgXml->createTextNode($this->getDescription())); $license->appendChild($pkgXml->createTextNode($this->getLicense())); if ($this->getLicenseUrl()) { $license->setAttribute("url", $this->getLicenseUrl()); } $releaseNote->appendChild($pkgXml->createTextNode($this->getReleaseNote())); if ($this->getStability()) { $stability->appendChild($pkgXml->createTextNode(Fox::getModel("extensionmanager/package/state")->getOptionText($this->getStability()))); } $date->appendChild($pkgXml->createTextNode(Fox_Core_Model_Date::getCurrentDate('Y-m-d H:i:s'))); $nodes = array($name, $version, $summary, $description, $license, $releaseNote, $stability, $date); foreach ($nodes as $node) { $extInfo->appendChild($node); } $pkgXml->appendChild($extInfo); if ($this->getProviders()) { $this->_prepareProviders(); } if ($this->getContentTreeData()) { $this->_prepareContentsTree(); } else { throw new Exception("Unknown contents"); } return true; }
/** * Returns path of xml file * * @return string */ public function getReportsFilePath() { $directoryPath = CACHE_DIR . DIRECTORY_SEPARATOR . 'analytics'; if (!file_exists($directoryPath)) { @mkdir($directoryPath, 0777); } $filePath = $directoryPath . DIRECTORY_SEPARATOR . 'report-' . Fox_Core_Model_Date::getCurrentDate('Y-m-d') . '.xml'; return $filePath; }
/** * Get formatted date * * @param Fox_Core_Model_Date $date * @param string $formatType Valid php formats * @param string|NULL $locale Uses default locale if NULL * @return string */ public function formatDate(Fox_Core_Model_Date $date, $formatType, $locale = NULL) { Fox_Core_Model_Date::setOptions(array('format_type' => 'php')); return $date->toString($formatType); }
/** * Save action */ public function saveAction() { if ($this->getRequest()->isPost()) { $data = $this->getRequest()->getPost(); try { $model = Fox::getModel('newsletter/template'); if ($id = $this->getRequest()->getParam('id')) { $model->load($id); } else { $data['create_date'] = Fox_Core_Model_Date::getCurrentDate('Y-m-d H:i:s'); } $data['update_date'] = Fox_Core_Model_Date::getCurrentDate('Y-m-d H:i:s'); $model->setData($data); $model->save(); Fox::getHelper('core/message')->addInfo('Template was successfully saved.'); if ($this->getRequest()->getParam('back')) { $this->sendRedirect('*/*/edit', array('id' => $model->getId())); return; } } catch (Exception $e) { Fox::getHelper('core/message')->addError($e->getMessage()); $this->sendRedirect('*/*/edit', array('id' => $model->getId())); } } $this->sendRedirect('*/*/'); }
/** * Forgot password action * * Sends an email with link to member which redirects to change password interface */ public function forgotPasswordAction() { if ($this->getRequest()->isPost()) { try { $data = $this->getRequest()->getPost(); $model = Fox::getModel('member/member'); $model->load($data['email_id'], 'email_id'); if ($model->getId()) { $code = strtolower(substr(md5(time() * mt_rand()), 0, 20)); $passwordModel = Fox::getModel('member/password'); $passwordModel->load($model->getId(), 'mem_id'); $passwordModel->setMemId($model->getId()); $passwordModel->setCode($code); $passwordModel->setCreatedOn(Fox_Core_Model_Date::getCurrentDate('Y-m-d H:i:s')); $passwordModel->save(); try { $modelTemplate = Fox::getModel('core/email/template'); $sender = Fox::getPreference('member/password/email_sender'); $template = Fox::getPreference('member/password/forgot_email'); $modelTemplate->sendTemplateMail($template, $model->getEmailId(), $sender, array('name' => $model->getFirstName(), 'link' => Fox::getUrl('*/password/change-password', array('code' => $code)))); } catch (Exception $e) { } Fox::getHelper('core/message')->setInfo('Change password link has been sent to your email.'); $this->sendRedirect('*/*/login'); } else { Fox::getHelper('core/message')->setError('Email Id was not found.'); } } catch (Exception $e) { Fox::getHelper('core/message')->setError($e->getMessage()); } } $this->loadLayout(); $this->renderLayout(); }