Skip to content

Commit

Permalink
Release/pattern matching (#14)
Browse files Browse the repository at this point in the history
* Add tawk-url-utils lib and used it to match the exclude/include urls
* Add an upgrade manager and handled backwards compatibility for pattern matching
* Fix version comparison to handle backwards compatibility
* Updated package structure and added function to check valid hostname instead of directly comparing to the base url
* Update readme for changelog and new package structure and added example patterns tooltip
* Added release workflow
* Updated build script to include new files on non-ocmod package
* Fix asset path for uploading artifacts

---------

Co-authored-by: Alvin Johnson So <[email protected]>
Co-authored-by: asyraf <[email protected]>
  • Loading branch information
3 people authored Apr 3, 2023
1 parent 72af31c commit 634eca2
Show file tree
Hide file tree
Showing 14 changed files with 569 additions and 84 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: create-release-artifact

on:
release:
types: [published]

jobs:
create-release-artifact:
name: Creating release artifact
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2

- name: cached dependencies
uses: actions/cache@v2
id: cached-dependencies
with:
path: ./vendor
# the key will change if composer.lock changes
key: ${{ runner.os }}-dependencies-${{ hashFiles('**/composer.lock') }}

- name: install dependencies
uses: php-actions/composer@v6
with:
command: run build:prod

- name: version
id: version
run: echo "::set-output name=version::$(jq -r '.version' ./composer.json)"

- name: build artifacts
run: composer run package

- name: upload regular artifact
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./tmp/tawk-oc2-${{ steps.version.outputs.version }}.zip
asset_name: tawk-oc2-${{ steps.version.outputs.version }}.zip
asset_content_type: application/zip

- name: upload ocmod artifact
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./tmp/tawk-oc2-${{ steps.version.outputs.version }}.ocmod.zip
asset_name: tawk-oc2-${{ steps.version.outputs.version }}.ocmod.zip
asset_content_type: application/zip
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
upload/
*.zip
docker/bin
/vendor
/docker/bin
/tmp
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ This section describes how to install the plugin and get it working.
> If you aren’t using the English language for the OpenCart admin area, copy the language file into the correct language folder. If you are not using the default OpenCart theme, be sure to paste tawkto.tpl in the correct theme folder.
* admin/controller/extension/module/tawkto.php -> `<opencart_folder>`/admin/controller/extension/module/
* admin/controller/extension/module/tawkto/ -> `<opencart_folder>`/admin/controller/extension/module/
* admin/language/english/extension/module/tawkto.php -> `<opencart_folder>`/admin/language/`<your_language>`/extension/module/
* admin/view/image/tawkto/ -> `<opencart_folder>`/admin/view/image/
* admin/view/template/extension/module/tawkto.tpl -> `<opencart_folder>`/admin/view/template/extension/module/
* admin/view/template/extension/module/tawkto/ -> `<opencart_folder>`/admin/view/template/extension/module/
* catalog/controller/extension/module/tawkto.php -> `<opencart_folder>`/catalog/controller/extension/module/tawkto.php
* catalog/view/theme/default/template/extension/module/tawkto.tpl -> `<opencart_folder>`/catalog/view/theme/`<your_theme>`/template/extension/module/tawkto.tpl

Expand All @@ -44,6 +46,9 @@ Visit our [Help Center](https://help.tawk.to/) for answers to FAQs

## Changelog

### 1.5.0
* Enhanced pattern matching for filtering pages to show/hide widgets.

### 1.4.1
* Added function for widget selection iframe to auto resize.
* Provided platform identifier to widget selection iframe.
Expand Down
21 changes: 20 additions & 1 deletion admin/controller/extension/module/tawkto.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/

define('PLUGIN_VERSION', '1.5.0');

require_once dirname(__FILE__) . '/tawkto/upgrades/manager.php';

class ControllerExtensionModuleTawkto extends Controller {
private $error = array();

Expand All @@ -26,6 +30,18 @@ private function setup() {
public function index() {
$this->setup();

// upgrade manager
$dependencies = array(
'model_setting' => $this->model_setting_setting,
'model_store' => $this->model_setting_store
);
$options = array(
'version' => PLUGIN_VERSION,
'version_var_name' => 'tawkto_version'
);
$upgrade_manager = new TawkToUpgradeManager($dependencies, $options);
$upgrade_manager->start();

$data = $this->setupIndexTexts();

// get current store and load tawk.to options
Expand Down Expand Up @@ -361,7 +377,10 @@ private function getBaseUrl() {

public function install() {
$this->setup();
$this->model_setting_setting->editSetting('tawkto', array("tawkto_status" => 1));
$this->model_setting_setting->editSetting('tawkto', array(
'tawkto_status' => 1,
'tawkto_version' => PLUGIN_VERSION
));

$this->enableAllLayouts();
}
Expand Down
115 changes: 107 additions & 8 deletions admin/view/template/extension/module/tawkto.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,47 @@
margin-top: 1rem;
}
}
/* Tooltip */
.tawk-tooltip {
position: relative;
display: inline;
color: #03a84e;
}
.tawk-tooltip .tawk-tooltiptext {
visibility: hidden;
background-color: #545454;
color: #fff;
text-align: center;
padding: 0.5rem;
max-width: 300px;
border-radius: 0.5rem;
font-size: 1.2rem;
line-height: 1;
/* Position the tooltip text - see examples below! */
position: absolute;
z-index: 1000;
top: 12px;
}
.tawk-tooltip .tawk-tooltiptext::before {
content: "";
display: block;
width: 0;
height: 0;
position: absolute;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 5px solid #545454;
top: -5px;
left: 5px;
}
.tawk-tooltip:hover .tawk-tooltiptext {
visibility: visible;
}
</style>
<?php echo $column_left; ?>
<div id="content">
Expand Down Expand Up @@ -94,10 +135,39 @@
<textarea class="form-control hide_specific" name="hide_oncustom" id="hide_oncustom" cols="30" rows="10"></textarea>
<?php endif; ?>
<br>
<p style="text-align: justify;">
Add URLs to pages in which you would like to hide the widget. ( if "always show" is checked )<br>
Put each URL in a new line.
</p>
<div style="text-align: justify;">
Add URLs/paths to pages in which you would like to hide the widget. ( if "always show" is checked )<br>
Put each URL/path in a new line. Paths should have a leading '/'.
<br>
<div class="tawk-tooltip">
Examples of accepted path patterns
<ul class="tawk-tooltiptext">
<li>*</li>
<li>*/to/somewhere</li>
<li>/*/to/somewhere</li>
<li>/path/*/somewhere</li>
<li>/path/*/lead/*/somewhere</li>
<li>/path/*/*/somewhere</li>
<li>/path/to/*</li>
<li>/path/to/*/</li>
<li>*/to/*/page</li>
<li>/*/to/*/page</li>
<li>/path/*/other/*</li>
<li>/path/*/other/*/</li>
<li>http://www.example.com/</li>
<li>http://www.example.com/*</li>
<li>http://www.example.com/*/to/somewhere</li>
<li>http://www.example.com/path/*/somewhere</li>
<li>http://www.example.com/path/*/lead/*/somewhere</li>
<li>http://www.example.com/path/*/*/somewhere</li>
<li>http://www.example.com/path/to/*</li>
<li>http://www.example.com/path/to/*/</li>
<li>http://www.example.com/*/to/*/page</li>
<li>http://www.example.com/path/*/other/*</li>
<li>http://www.example.com/path/*/other/*/</li>
</ul>
</div>
</div>
</div>
</div>
<div class="form-group col-lg-12">
Expand Down Expand Up @@ -126,10 +196,39 @@
<textarea class="form-control show_specific" name="show_oncustom" id="show_oncustom" cols="30" rows="10"></textarea>
<?php endif; ?>
<br>
<p style="text-align: justify;">
Add URLs to pages in which you would like to show the widget.<br>
Put each URL in a new line.
</p>
<div style="text-align: justify;">
Add URLs/paths to pages in which you would like to show the widget.<br>
Put each URL/path in a new line. Paths should have a leading '/'.
<br>
<div class="tawk-tooltip">
Examples of accepted path patterns
<ul class="tawk-tooltiptext">
<li>*</li>
<li>*/to/somewhere</li>
<li>/*/to/somewhere</li>
<li>/path/*/somewhere</li>
<li>/path/*/lead/*/somewhere</li>
<li>/path/*/*/somewhere</li>
<li>/path/to/*</li>
<li>/path/to/*/</li>
<li>*/to/*/page</li>
<li>/*/to/*/page</li>
<li>/path/*/other/*</li>
<li>/path/*/other/*/</li>
<li>http://www.example.com/</li>
<li>http://www.example.com/*</li>
<li>http://www.example.com/*/to/somewhere</li>
<li>http://www.example.com/path/*/somewhere</li>
<li>http://www.example.com/path/*/lead/*/somewhere</li>
<li>http://www.example.com/path/*/*/somewhere</li>
<li>http://www.example.com/path/to/*</li>
<li>http://www.example.com/path/to/*/</li>
<li>http://www.example.com/*/to/*/page</li>
<li>http://www.example.com/path/*/other/*</li>
<li>http://www.example.com/path/*/other/*/</li>
</ul>
</div>
</div>
</div>
</div>
<br><br>
Expand Down
36 changes: 18 additions & 18 deletions build-package.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
#!/bin/sh

if [ -z "$1" ]
then
echo "Release version wasn't specified";
return;
fi
release_version=$(jq -r '.version' ./composer.json);

release_version=$1;
echo "Creating temporary directory"
rm -rf ./tmp;
mkdir -p ./tmp/upload;
mkdir -p ./tmp/admin/controller/extension/module/tawkto;
mkdir -p ./tmp/catalog/controller/extension/module/tawkto;

echo "Creating temporary upload directory"
rm -rf ./upload
mkdir ./upload

echo "Copying files to upload directory"
cp -r admin ./upload/
cp -r catalog ./upload/
echo "Copying files"
cp README.md ./tmp;
cp -r admin ./tmp;
cp -r catalog ./tmp;
cp -r upgrades ./tmp/admin/controller/extension/module/tawkto;
cp -r vendor ./tmp/admin/controller/extension/module/tawkto;
cp -r vendor ./tmp/catalog/controller/extension/module/tawkto;
cp -r ./tmp/admin ./tmp/upload;
cp -r ./tmp/catalog ./tmp/upload;

echo "Creating opencart 3 zip files"
zip -9 -rq tawk-oc2-$release_version.ocmod.zip upload README.md
zip -9 -rq tawk-oc2-$release_version.zip admin catalog README.md

echo "Cleaning up"
rm -rf ./upload
echo "Creating opencart 2 zip files"
$(cd ./tmp && zip -9 -rq tawk-oc2-$release_version.ocmod.zip upload README.md);
$(cd ./tmp && zip -9 -rq tawk-oc2-$release_version.zip admin catalog README.md);

echo "Done!"
Loading

0 comments on commit 634eca2

Please sign in to comment.