Skip to content

Commit

Permalink
Compliance with CiviCRM 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
VangelisP committed Mar 27, 2019
1 parent bf39c39 commit 7255168
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 50 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog

* v1.1.1 :

* Proper menu structure

* v1.1 :

* Change of menu and URL path
Expand Down
22 changes: 12 additions & 10 deletions CRM/Mailreader/Form/Mailreader.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
+--------------------------------------------------------------------+
*/

use CRM_Mailreader_ExtensionUtil as E;

class CRM_Mailreader_Form_Mailreader extends CRM_Core_Form {

public $_action;
Expand All @@ -25,22 +27,22 @@ function buildQuickForm() {
$skip = FALSE;

// Set page title
CRM_Utils_System::setTitle(ts('Stored Email viewer'));
CRM_Utils_System::setTitle(E::ts('Stored Email viewer'));

// Fetch the mailing preferences
$mailingInfo = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailing_backend');

if ($mailingInfo['outBound_option'] != '5') {
// Issue a warning and do nothing
$url = CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1');
$warning = ts('Your <a href="%1">CiviCRM mailer option</a> is not set to <strong>"Redirect to Database"</strong>. I got nothing to show you.', array("1" => $url, 'domain' => 'com.ixiam.modules.mailreader'));
$warning = E::ts('Your <a href="%1">CiviCRM mailer option</a> is not set to <strong>"Redirect to Database"</strong>. I got nothing to show you.', array("1" => $url, 'domain' => 'com.ixiam.modules.mailreader'));
$skip = TRUE;
}
else {
// Limit to X rows by default
$this->add('text', 'limit_to', ts('Limit to: ', array('domain' => 'com.ixiam.modules.mailreader')), array('size' => 6, 'maxlength' => 6));
$this->add('text', 'limit_to', E::ts('Limit to: ', array('domain' => 'com.ixiam.modules.mailreader')), array('size' => 6, 'maxlength' => 6));
// Show last rows first, by default
$this->add('checkbox', 'show_last', ts('Show in DESCending order', array('domain' => 'com.ixiam.modules.mailreader')));
$this->add('checkbox', 'show_last', E::ts('Show in DESCending order', array('domain' => 'com.ixiam.modules.mailreader')));
// Count how many rows do we have
$countrows = $this->countlog();
// Populate the table
Expand All @@ -63,12 +65,12 @@ function buildQuickForm() {
array(
'type' => 'refresh',
'subName' => 'refresh',
'name' => ts('Refresh listing', array('domain' => 'com.ixiam.modules.mailreader')),
'name' => E::ts('Refresh listing', array('domain' => 'com.ixiam.modules.mailreader')),
),
array(
'type' => 'submit',
'subName' => 'delete_all',
'name' => ts('Delete ALL entries', array('domain' => 'com.ixiam.modules.mailreader')),
'name' => E::ts('Delete ALL entries', array('domain' => 'com.ixiam.modules.mailreader')),
),
));

Expand Down Expand Up @@ -126,7 +128,7 @@ public function postProcess() {
// We will now be deleting all the log entries
$this->deletelog();
// After deletion, redirect
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/emailviewer', '&reset=1'));
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/mailreader', '&reset=1'));
}

if (isset($params['limit_to']) && isset($params['_qf_Mailreader_refresh_refresh'])) {
Expand All @@ -139,7 +141,7 @@ public function postProcess() {
$urlParams .= '&order=ASC';
}
$urlParams .= '&reset=1';
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/emailviewer', $urlParams));
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/mailreader', $urlParams));
}

// Export the selected email into .eml format
Expand All @@ -149,8 +151,8 @@ public function postProcess() {
$exportable_filename = 'mail_' . date_timestamp_get(date_create()) . '.eml';
$output_file = self::write_to_csv($selected_record, 'mailreader', $exportable_filename);

$status = ts('Right click <a href="%1">here</a> and "Save target as ..." to save the exported EML file', array(1 => $output_file));
CRM_Core_Session::setStatus($status, ts("Exported to EML", array()), 'success', array('expires' => 0));
$status = E::ts('Right click <a href="%1">here</a> and "Save target as ..." to save the exported EML file', array(1 => $output_file));
CRM_Core_Session::setStatus($status, E::ts("Exported to EML", array()), 'success', array('expires' => 0));
}
}

Expand Down
5 changes: 3 additions & 2 deletions info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<description>Gives admin(s) the ability to view, through a simple UI, the stored messages and their headers, that are redirected to the database through the 'Redirect to database' option</description>
<license>AGPL-3.0</license>
<maintainer>
<author>Vangelis Pantazis @ iXiam Global Solutions</author>
<author>iXiam Global Solutions</author>
<email>[email protected]</email>
</maintainer>
<urls>
Expand All @@ -14,11 +14,12 @@
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2018-04-30</releaseDate>
<version>1.1</version>
<version>1.1.1</version>
<develStage>stable</develStage>
<compatibility>
<ver>4.6</ver>
<ver>4.7</ver>
<ver>5.0</ver>
</compatibility>
<comments>A simple extension that reads from the database the redirected emails</comments>
<civix>
Expand Down
128 changes: 113 additions & 15 deletions mailreader.civix.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,83 @@

// AUTO-GENERATED FILE -- Civix may overwrite any changes made to this file

/**
* The ExtensionUtil class provides small stubs for accessing resources of this
* extension.
*/
class CRM_Mailreader_ExtensionUtil {
const SHORT_NAME = "mailreader";
const LONG_NAME = "com.ixiam.modules.mailreader";
const CLASS_PREFIX = "CRM_Mailreader";

/**
* Translate a string using the extension's domain.
*
* If the extension doesn't have a specific translation
* for the string, fallback to the default translations.
*
* @param string $text
* Canonical message text (generally en_US).
* @param array $params
* @return string
* Translated text.
* @see ts
*/
public static function ts($text, $params = array()) {
if (!array_key_exists('domain', $params)) {
$params['domain'] = array(self::LONG_NAME, NULL);
}
return ts($text, $params);
}

/**
* Get the URL of a resource file (in this extension).
*
* @param string|NULL $file
* Ex: NULL.
* Ex: 'css/foo.css'.
* @return string
* Ex: 'http://example.org/sites/default/ext/org.example.foo'.
* Ex: 'http://example.org/sites/default/ext/org.example.foo/css/foo.css'.
*/
public static function url($file = NULL) {
if ($file === NULL) {
return rtrim(CRM_Core_Resources::singleton()->getUrl(self::LONG_NAME), '/');
}
return CRM_Core_Resources::singleton()->getUrl(self::LONG_NAME, $file);
}

/**
* Get the path of a resource file (in this extension).
*
* @param string|NULL $file
* Ex: NULL.
* Ex: 'css/foo.css'.
* @return string
* Ex: '/var/www/example.org/sites/default/ext/org.example.foo'.
* Ex: '/var/www/example.org/sites/default/ext/org.example.foo/css/foo.css'.
*/
public static function path($file = NULL) {
// return CRM_Core_Resources::singleton()->getPath(self::LONG_NAME, $file);
return __DIR__ . ($file === NULL ? '' : (DIRECTORY_SEPARATOR . $file));
}

/**
* Get the name of a class within this extension.
*
* @param string $suffix
* Ex: 'Page_HelloWorld' or 'Page\\HelloWorld'.
* @return string
* Ex: 'CRM_Foo_Page_HelloWorld'.
*/
public static function findClass($suffix) {
return self::CLASS_PREFIX . '_' . str_replace('\\', '_', $suffix);
}

}

use CRM_Mailreader_ExtensionUtil as E;

/**
* (Delegated) Implements hook_civicrm_config().
*
Expand All @@ -19,14 +96,14 @@ function _mailreader_civix_civicrm_config(&$config = NULL) {
$extRoot = dirname(__FILE__) . DIRECTORY_SEPARATOR;
$extDir = $extRoot . 'templates';

if ( is_array( $template->template_dir ) ) {
array_unshift( $template->template_dir, $extDir );
if (is_array($template->template_dir)) {
array_unshift($template->template_dir, $extDir);
}
else {
$template->template_dir = array( $extDir, $template->template_dir );
$template->template_dir = array($extDir, $template->template_dir);
}

$include_path = $extRoot . PATH_SEPARATOR . get_include_path( );
$include_path = $extRoot . PATH_SEPARATOR . get_include_path();
set_include_path($include_path);
}

Expand Down Expand Up @@ -131,7 +208,7 @@ function _mailreader_civix_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
* @return CRM_Mailreader_Upgrader
*/
function _mailreader_civix_upgrader() {
if (!file_exists(__DIR__.'/CRM/Mailreader/Upgrader.php')) {
if (!file_exists(__DIR__ . '/CRM/Mailreader/Upgrader.php')) {
return NULL;
}
else {
Expand Down Expand Up @@ -167,7 +244,8 @@ function _mailreader_civix_find_files($dir, $pattern) {
while (FALSE !== ($entry = readdir($dh))) {
$path = $subdir . DIRECTORY_SEPARATOR . $entry;
if ($entry{0} == '.') {
} elseif (is_dir($path)) {
}
elseif (is_dir($path)) {
$todos[] = $path;
}
}
Expand All @@ -189,7 +267,10 @@ function _mailreader_civix_civicrm_managed(&$entities) {
$es = include $file;
foreach ($es as $e) {
if (empty($e['module'])) {
$e['module'] = 'com.ixiam.modules.mailreader';
$e['module'] = E::LONG_NAME;
}
if (empty($e['params']['version'])) {
$e['params']['version'] = '3';
}
$entities[] = $e;
}
Expand Down Expand Up @@ -218,7 +299,7 @@ function _mailreader_civix_civicrm_caseTypes(&$caseTypes) {
// throw new CRM_Core_Exception($errorMessage);
}
$caseTypes[$name] = array(
'module' => 'com.ixiam.modules.mailreader',
'module' => E::LONG_NAME,
'name' => $name,
'file' => $file,
);
Expand All @@ -244,7 +325,7 @@ function _mailreader_civix_civicrm_angularModules(&$angularModules) {
$name = preg_replace(':\.ang\.php$:', '', basename($file));
$module = include $file;
if (empty($module['ext'])) {
$module['ext'] = 'com.ixiam.modules.mailreader';
$module['ext'] = E::LONG_NAME;
}
$angularModules[$name] = $module;
}
Expand All @@ -271,8 +352,10 @@ function _mailreader_civix_glob($pattern) {
* Inserts a navigation menu item at a given place in the hierarchy.
*
* @param array $menu - menu hierarchy
* @param string $path - path where insertion should happen (ie. Administer/System Settings)
* @param array $item - menu you need to insert (parent/child attributes will be filled for you)
* @param string $path - path to parent of this item, e.g. 'my_extension/submenu'
* 'Mailing', or 'Administer/System Settings'
* @param array $item - the item to insert (parent/child attributes will be
* filled for you)
*/
function _mailreader_civix_insert_navigation_menu(&$menu, $path, $item) {
// If we are done going down the path, insert menu
Expand All @@ -287,12 +370,14 @@ function _mailreader_civix_insert_navigation_menu(&$menu, $path, $item) {
}
else {
// Find an recurse into the next level down
$found = false;
$found = FALSE;
$path = explode('/', $path);
$first = array_shift($path);
foreach ($menu as $key => &$entry) {
if ($entry['attributes']['name'] == $first) {
if (!$entry['child']) $entry['child'] = array();
if (!isset($entry['child'])) {
$entry['child'] = array();
}
$found = _mailreader_civix_insert_navigation_menu($entry['child'], implode('/', $path), $item, $key);
}
}
Expand All @@ -319,7 +404,7 @@ function _mailreader_civix_fixNavigationMenu(&$nodes) {
if ($key === 'navID') {
$maxNavID = max($maxNavID, $item);
}
});
});
_mailreader_civix_fixNavigationMenuItems($nodes, $maxNavID, NULL);
}

Expand Down Expand Up @@ -356,7 +441,20 @@ function _mailreader_civix_civicrm_alterSettingsFolders(&$metaDataFolders = NULL
$configured = TRUE;

$settingsDir = __DIR__ . DIRECTORY_SEPARATOR . 'settings';
if(is_dir($settingsDir) && !in_array($settingsDir, $metaDataFolders)) {
if (is_dir($settingsDir) && !in_array($settingsDir, $metaDataFolders)) {
$metaDataFolders[] = $settingsDir;
}
}

/**
* (Delegated) Implements hook_civicrm_entityTypes().
*
* Find any *.entityType.php files, merge their content, and return.
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_entityTypes
*/

function _mailreader_civix_civicrm_entityTypes(&$entityTypes) {
$entityTypes = array_merge($entityTypes, array (
));
}
33 changes: 10 additions & 23 deletions mailreader.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,27 +139,14 @@ function mailreader_civicrm_preProcess($formName, &$form) {
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_navigationMenu
*/
function mailreader_civicrm_navigationMenu(&$menu) {
$pages = array(
'admin_page' => array(
'label' => ts('View stored email log', array('domain' => 'com.ixiam.modules.mailreader')),
'name' => ts('Stored Email reader', array('domain' => 'com.ixiam.modules.mailreader')),
'url' => 'civicrm/admin/emailviewer',
'parent' => array('Administer', 'Administration Console'),
'permission' => 'administer CiviCRM',
'operator' => 'AND',
'separator' => NULL,
'active' => 1,
),
);
foreach ($pages as $item) {
// Check that our item doesn't already exist.
$menu_item_search = array('url' => $item['url']);
$menu_items = array();
CRM_Core_BAO_Navigation::retrieve($menu_item_search, $menu_items);
if (empty($menu_items)) {
$path = implode('/', $item['parent']);
unset($item['parent']);
_mailreader_civix_insert_navigation_menu($menu, $path, $item);
}
}
$parent_path = "Administer/Administration Console";
_mailreader_civix_insert_navigation_menu($menu, $parent_path, array(
'label' => E::ts('View E-mail Log', array('domain' => 'com.ixiam.modules.mailreader')),
'name' => 'stored_email_reader',
'url' => 'civicrm/admin/mailreader',
'permission' => 'administer CiviCRM',
'operator' => '',
'separator' => NULL,
'active' => 1
));
}

0 comments on commit 7255168

Please sign in to comment.