Commit f93b4fb1 authored by bgm's avatar bgm Committed by Aegir user

Remove mosaico, it's in the platform, and KAM is now in core.

parent 547a6808
# APIv3
CiviCRM's APIv3 framework provides a way for consumers to manage data and call services. APIv3 can be called in many ways
(such as PHP, REST, and CLI). For a general introduction, see [APIv3 Intro](https://docs.civicrm.org/dev/en/latest/api/).
This extension defines a few new APIs:
* `Job.mosaico_migrate`: If you need to perform an automated migration from v1.x to v2.x, use this API to copy all
v1.x templates to v2.x.
* `Job.mosaico_purge`: If you need to perform an automated migration from v1.x to v2.x, use this API to clear out the
old v1.x templates.
* `MosaicoTemplate.*`: This API provides access to the user-configurable templates. It supports all standard CRUD
actions (`get`, `create`, `delete`etc). Its data-structure closely adheres to Mosaico's canonical storage format.
* `MosaicoBaseTemplate.get`: This API provides access to the *base templates*. A base template (such as `versafix-1`)
defines the HTML blocks that are available for drag/drop in the Mosaico palette. Note: This API is *read-only*.
To define custom templates, see the section on "Base templates".
# Base templates
A base template defines the HTML blocks that are available for drag/drop in the Mosaico palette. The standard distribution
of Mosaico includes a few base templates, such as `versafix-1`.
The upstream Mosaico project provides a tutorial on how to develop a custom base template:
https://github.com/voidlabs/mosaico/blob/master/templates/tutorial/mosaico-tutorial.md
The new template is essentially a folder with a couple standard files. Once you've developed these files, you'll need
a way to *deploy* the folder, such as:
* __Drop-in folder__: On any site, create a folder dedicated to custom base templates. By default, this is
`[civicrm.files]/mosaico_tpl`. (`[civicrm.files]` is a variable that resolves somewhere under the CMS's data
folder.) For example, if you deployed a template `foobar` on a typical Drupal 7 site, the full path to the template HTML
might be `/var/www/sites/default/files/civicrm/mosaico_tpl/foobar/template-foobar.html`. (The folder name can be
customized in "Administer => CiviMail => Mosaico Settings".)
* __Extension__: Create a CiviCRM extension and put the template in it. Use the [hook system](https://docs.civicrm.org/dev/en/latest/hooks/) to register the template via `hook_civicrm_mosaicoBaseTemplates`. For example, this snippet shows how an extension named `mymodule` can register a base-template named `foobar`:
```php
<?php
use CRM_Mymodule_ExtensionUtil as E;
function mymodule_civicrm_mosaicoBaseTemplates(&$templates) {
$templates['foobar'] = array(
'name' => 'foobar',
'title' => 'Foo Bar',
'path' => E::url('foobar/template-foobar.html'),
'thumbnail' => E::url('foobar/edres/_full.png'),
);
}
```
# Delivery
After designing a mailing, email messages are composed and delivered through FlexMailer. To programmaticaly tap into the
composition and delivery process, see the [FlexMailer developer docs](https://docs.civicrm.org/flexmailer/en/latest/).
<?php
class CRM_Mosaico_BAO_MosaicoTemplate extends CRM_Mosaico_DAO_MosaicoTemplate {
/**
* Create a new MosaicoTemplate based on array-data
*
* @param array $params key-value pairs
* @return CRM_Mosaico_DAO_MosaicoTemplate|NULL
*
public static function create($params) {
$className = 'CRM_Mosaico_DAO_MosaicoTemplate';
$entityName = 'MosaicoTemplate';
$hook = empty($params['id']) ? 'create' : 'edit';
CRM_Utils_Hook::pre($hook, $entityName, CRM_Utils_Array::value('id', $params), $params);
$instance = new $className();
$instance->copyValues($params);
$instance->save();
CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance);
return $instance;
} */
/**
* @return mixed
*/
public static function findBaseTemplates() {
if (!isset(Civi::$statics[__CLASS__]['bases'])) {
$templatesDir = CRM_Core_Resources::singleton()->getPath('uk.co.vedaconsulting.mosaico');
if (!$templatesDir) {
return FALSE;
}
$templatesDir .= '/packages/mosaico/templates';
if (!is_dir($templatesDir)) {
return FALSE;
}
$templatesUrl = CRM_Mosaico_Utils::getTemplatesUrl('absolute');
$templatesLocation[] = array('dir' => $templatesDir, 'url' => $templatesUrl);
$customTemplatesDir = \Civi::paths()->getPath(CRM_Core_BAO_Setting::getItem('Mosaico Preferences', 'mosaico_custom_templates_dir'));
$customTemplatesUrl = \Civi::paths()->getUrl(CRM_Core_BAO_Setting::getItem('Mosaico Preferences', 'mosaico_custom_templates_url'));
if (!is_null($customTemplatesDir) && !is_null($customTemplatesUrl)) {
if (is_dir($customTemplatesDir)) {
$templatesLocation[] = array('dir' => $customTemplatesDir, 'url' => $customTemplatesUrl);
}
}
$records = array();
foreach ($templatesLocation as $templateLocation) {
foreach (glob("{$templateLocation['dir']}/*", GLOB_ONLYDIR) as $dir) {
$template = basename($dir);
$templateHTML = "{$templateLocation['url']}/{$template}/template-{$template}.html";
$templateThumbnail = "{$templateLocation['url']}/{$template}/edres/_full.png";
$records[$template] = array(
'name' => $template,
'title' => $template,
'thumbnail' => $templateThumbnail,
'path' => $templateHTML,
);
}
}
if (class_exists('\Civi\Core\Event\GenericHookEvent')) {
\Civi::dispatcher()->dispatch('hook_civicrm_mosaicoBaseTemplates',
\Civi\Core\Event\GenericHookEvent::create(array(
'templates' => &$records,
))
);
}
Civi::$statics[__CLASS__]['bases'] = $records;
}
return Civi::$statics[__CLASS__]['bases'];
}
}
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2015
*
* Generated from xml/schema/CRM/Mosaico/MessageTemplate.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
*/
require_once 'CRM/Core/DAO.php';
require_once 'CRM/Utils/Type.php';
class CRM_Mosaico_DAO_MessageTemplate extends CRM_Core_DAO
{
/**
* static instance to hold the table name
*
* @var string
*/
static $_tableName = 'civicrm_mosaico_msg_template';
/**
* static instance to hold the field values
*
* @var array
*/
static $_fields = null;
/**
* static instance to hold the keys used in $_fields for each field.
*
* @var array
*/
static $_fieldKeys = null;
/**
* static instance to hold the FK relationships
*
* @var string
*/
static $_links = null;
/**
* static instance to hold the values that can
* be imported
*
* @var array
*/
static $_import = null;
/**
* static instance to hold the values that can
* be exported
*
* @var array
*/
static $_export = null;
/**
* static value to see if we should log any modifications to
* this table in the civicrm_log table
*
* @var boolean
*/
static $_log = true;
/**
* Unique Settings ID
*
* @var int unsigned
*/
public $id;
/**
* FK to civicrm_msg_template.
*
* @var int unsigned
*/
public $msg_tpl_id;
/**
*
* @var string
*/
public $hash_key;
/**
* name
*
* @var string
*/
public $name;
/**
* HTML
*
* @var longtext
*/
public $html;
/**
* metadata
*
* @var longtext
*/
public $metadata;
/**
* template
*
* @var longtext
*/
public $template;
/**
* class constructor
*
* @return civicrm_mosaico_msg_template
*/
function __construct()
{
$this->__table = 'civicrm_mosaico_msg_template';
parent::__construct();
}
/**
* Returns foreign keys and entity references
*
* @return array
* [CRM_Core_Reference_Interface]
*/
static function getReferenceColumns()
{
if (!self::$_links) {
self::$_links = static ::createReferenceColumns(__CLASS__);
self::$_links[] = new CRM_Core_Reference_Basic(self::getTableName() , 'msg_tpl_id', 'civicrm_msg_template', 'id');
}
return self::$_links;
}
/**
* Returns all the column names of this table
*
* @return array
*/
static function &fields()
{
if (!(self::$_fields)) {
self::$_fields = array(
'id' => array(
'name' => 'id',
'type' => CRM_Utils_Type::T_INT,
'description' => 'Unique Settings ID',
'required' => true,
) ,
'msg_tpl_id' => array(
'name' => 'msg_tpl_id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('message template ID') ,
'description' => 'FK to civicrm_msg_template.',
'required' => true,
'FKClassName' => 'CRM_Core_DAO_MessageTemplate',
'html' => array(
'type' => 'Select',
) ,
'pseudoconstant' => array(
'table' => 'civicrm_msg_template',
'keyColumn' => 'id',
'labelColumn' => 'msg_title',
)
) ,
'hash_key' => array(
'name' => 'hash_key',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('hash_key') ,
'maxlength' => 32,
'size' => CRM_Utils_Type::MEDIUM,
) ,
'name' => array(
'name' => 'name',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('name') ,
'description' => 'name',
'maxlength' => 32,
'size' => CRM_Utils_Type::MEDIUM,
) ,
'html' => array(
'name' => 'html',
'type' => CRM_Utils_Type::T_LONGTEXT,
'title' => ts('HTML') ,
'description' => 'HTML',
'html' => array(
'type' => 'RichTextEditor',
) ,
) ,
'metadata' => array(
'name' => 'metadata',
'type' => CRM_Utils_Type::T_LONGTEXT,
'title' => ts('metadata') ,
'description' => 'metadata',
'html' => array(
'type' => 'RichTextEditor',
) ,
) ,
'template' => array(
'name' => 'template',
'type' => CRM_Utils_Type::T_LONGTEXT,
'title' => ts('template') ,
'description' => 'template',
'html' => array(
'type' => 'RichTextEditor',
) ,
) ,
);
}
return self::$_fields;
}
/**
* Returns an array containing, for each field, the arary key used for that
* field in self::$_fields.
*
* @return array
*/
static function &fieldKeys()
{
if (!(self::$_fieldKeys)) {
self::$_fieldKeys = array(
'id' => 'id',
'msg_tpl_id' => 'msg_tpl_id',
'hash_key' => 'hash_key',
'name' => 'name',
'html' => 'html',
'metadata' => 'metadata',
'template' => 'template',
);
}
return self::$_fieldKeys;
}
/**
* Returns the names of this table
*
* @return string
*/
static function getTableName()
{
return self::$_tableName;
}
/**
* Returns if this table needs to be logged
*
* @return boolean
*/
function getLog()
{
return self::$_log;
}
/**
* Returns the list of fields that can be imported
*
* @param bool $prefix
*
* @return array
*/
static function &import($prefix = false)
{
if (!(self::$_import)) {
self::$_import = array();
$fields = self::fields();
foreach($fields as $name => $field) {
if (CRM_Utils_Array::value('import', $field)) {
if ($prefix) {
self::$_import['mosaico_msg_template'] = & $fields[$name];
} else {
self::$_import[$name] = & $fields[$name];
}
}
}
}
return self::$_import;
}
/**
* Returns the list of fields that can be exported
*
* @param bool $prefix
*
* @return array
*/
static function &export($prefix = false)
{
if (!(self::$_export)) {
self::$_export = array();
$fields = self::fields();
foreach($fields as $name => $field) {
if (CRM_Utils_Array::value('export', $field)) {
if ($prefix) {
self::$_export['mosaico_msg_template'] = & $fields[$name];
} else {
self::$_export[$name] = & $fields[$name];