diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..7344e81 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "vendor/jquery-references"] + path = vendor/jquery-references + url = https://github.com/davidstutz/jquery-references diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..3509043 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,7 @@ +Copyright (C) 2017 David Stutz + +This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. + +This program 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 General Public License for more details. + +See [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/). \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..eb32064 --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +# Wordpress References + +Small and naive plugin to easily create labels and references as in LaTeX/BibTeX based on [davidstutz/jquery-references](https://github.com/davidstutz/jquery-references) + +## Installation + +In `wp-content/plugins`, create a new folder `wordpress-references` and put all files within this repository in this folder. In the backend, go to "Plugins" -> "Installed Plugins" and activate "Wordpress References". + +## Usage + +There are two forms of usage; the shorthand verison for placing a new label is + + [lbl name scope] + +This will put a label at this place. Now using + + [ref name scope] + +will place a reference to the label with the same name and in the same scope. Labels always start counting with 1; and counting is done separately for each scope. This means that + + [lbl fig1 figures] + [ref fig1 figures] + [lbl ref1 references] + [ref ref1 references] + +will output four times `1`, as the two created labels live in separate scopes. + +The longer notation for both shortcodes are + + [lbl name="fig1" scope="figures] + [ref name="fig1" scope="figures] + +The shorthand version and the explicit version should **not** be mixed, e.g. as follows: + + [lbl name="fig1" figures] // will not work! + [lbl fig1 scope="figures"] // will not work! + +To directly place the labels in brackets: + + [lblb ref1 references] + [refb ref1 references] + +## License + +Copyright (C) 2017 David Stutz + +This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. + +This program 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 General Public License for more details. + +See [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/). \ No newline at end of file diff --git a/references.php b/references.php new file mode 100644 index 0000000..56c28cb --- /dev/null +++ b/references.php @@ -0,0 +1,188 @@ + '', + 'scope' => '', + 'style' => '###', + ), $attributes)); + + if (References::$_included === FALSE) { + wp_enqueue_script('jquery-references', plugins_url('/vendor/jquery-references/dist/js/jquery-references.js', __FILE__)); + wp_enqueue_script('jquery-references', plugins_url('/vendor/jquery-references/docs/js/jquery-3.1.1.min.js', __FILE__)); + References::$_included = TRUE; + } + + if (isset($attributes[0])) { + $name = $attributes[0]; + } + + if (isset($attributes[1])) { + $scope = $attributes[1]; + } + else if (empty($scope)) { + $scope = 'default'; + } + + if (empty($style) OR FALSE == strpos($style, '###')) { + $style = '###'; + } + + if (!empty($name) AND !empty($scope)) { + + $javascript = ''; + if (!isset(References::$_scopes[$scope])) { + $javascript = ''; + References::$_scopes[$scope] = TRUE; + } + + return $javascript . str_replace('###', '', $style); + } + } + + /** + * Add a label. + * + * @param string $content + * @param array $attributes + * @return string + */ + public static function lbl($attributes, $content = null) { + extract(shortcode_atts(array( + 'name' => '', + 'scope' => '', + 'style' => '###', + ), $attributes)); + + if (References::$_included === FALSE) { + wp_enqueue_script('jquery-references', plugins_url('/vendor/jquery-references/dist/js/jquery-references.js', __FILE__)); + wp_enqueue_script('jquery-references', plugins_url('/vendor/jquery-references/docs/js/jquery-3.1.1.min.js', __FILE__)); + References::$_included = TRUE; + } + + if (isset($attributes[0])) { + $name = $attributes[0]; + } + + if (isset($attributes[1])) { + $scope = $attributes[1]; + } + else if (empty($scope)) { + $scope = 'default'; + } + + if (empty($style) OR FALSE == strpos($style, '###')) { + $style = '###'; + } + + if (!empty($name) AND !empty($scope)) { + + $name = $name; + if (isset($attributes[1])) { + $name = $attributes[1]; + } + + $scope = $scope; + if (isset($attributes[0])) { + $name = $attributes[0]; + } + + $javascript = ''; + if (!isset(References::$_scopes[$scope])) { + $javascript = ''; + References::$_scopes[$scope] = TRUE; + } + + return $javascript . str_replace('###', '', $style); + } + } + + /** + * Add a reference to an existing label. + * + * @param string $content + * @param array $attributes + * @return string + */ + public static function refb($attributes, $content = null) { + $attributes['style'] = '[###]'; + return References::ref($attributes, $content); + } + + /** + * Add a label. + * + * @param string $content + * @param array $attributes + * @return string + */ + public static function lblb($attributes, $content = null) { + $attributes['style'] = '[###]'; + return References::lbl($attributes, $content); + } +} + +References::init(); \ No newline at end of file diff --git a/vendor/jquery-references b/vendor/jquery-references new file mode 160000 index 0000000..028c309 --- /dev/null +++ b/vendor/jquery-references @@ -0,0 +1 @@ +Subproject commit 028c309c69918b4265f6e2f673057451375e6f73