1 | <?php |
||
2 | /* |
||
3 | Plugin Name: Piwigo to MediaWiki |
||
4 | Version: 0.1.0 |
||
5 | Description: A Piwigo plugin for exporting photos to MediaWiki wikis. |
||
6 | Plugin URI: auto |
||
7 | Author: Sam Wilson |
||
8 | Author URI: https://samwilson.id.au |
||
9 | */ |
||
10 | |||
11 | // Make sure we're already in Piwigo. |
||
12 | defined('PHPWG_ROOT_PATH') or exit(1); |
||
0 ignored issues
–
show
|
|||
13 | |||
14 | // Define plugin's paths etc. |
||
15 | define('PIWIGO2MEDIAWIKI_ID', 'piwigo2mediawiki'); |
||
16 | define('PIWIGO2MEDIAWIKI_PATH', PHPWG_PLUGINS_PATH.PIWIGO2MEDIAWIKI_ID.'/'); |
||
17 | define('PIWIGO2MEDIAWIKI_PAGE', 'plugin-'.PIWIGO2MEDIAWIKI_ID); |
||
18 | define( |
||
19 | 'PIWIGO2MEDIAWIKI_ADMIN', |
||
20 | get_absolute_root_url().'admin.php?page=plugin-'.PIWIGO2MEDIAWIKI_ID |
||
21 | ); |
||
22 | define( |
||
23 | 'PIWIGO2MEDIAWIKI_DIR', |
||
24 | realpath(PHPWG_PLUGINS_PATH.PIWIGO2MEDIAWIKI_ID).'/' |
||
25 | ); |
||
26 | |||
27 | // Complain if our plugin directory is not named correctly. |
||
28 | if (basename(dirname(__FILE__)) != PIWIGO2MEDIAWIKI_ID) { |
||
29 | add_event_handler('init', function () { |
||
30 | global $page; |
||
31 | $page['errors'][] = l10n( |
||
32 | 'Plugin folder name is incorrect, please rename %s to %s', |
||
33 | basename(dirname(__FILE__)), |
||
34 | PIWIGO2MEDIAWIKI_ID |
||
35 | ); |
||
36 | }); |
||
37 | return; |
||
38 | } |
||
39 | |||
40 | //Initialise the plugin. |
||
41 | add_event_handler('init', function(){ |
||
42 | global $conf; |
||
43 | load_language('plugin.lang', PIWIGO2MEDIAWIKI_PATH); |
||
44 | if (isset($conf['piwigo2mediawiki'])) { |
||
45 | $conf['piwigo2mediawiki'] = safe_unserialize($conf['piwigo2mediawiki']); |
||
46 | } |
||
47 | }); |
||
48 | |||
49 | // Add event handlers. |
||
50 | if (defined('IN_ADMIN')) { |
||
51 | |||
52 | // Add the admin menu item. |
||
53 | add_event_handler('get_admin_plugin_menu_links', function($menu) { |
||
54 | $menu[] = array( |
||
55 | 'NAME' => l10n('Piwigo to MediaWiki'), |
||
56 | 'URL' => PIWIGO2MEDIAWIKI_ADMIN, |
||
57 | ); |
||
58 | return $menu; |
||
59 | }); |
||
60 | |||
61 | // Add the send-to-MediaWiki global action. |
||
62 | add_event_handler('loc_end_element_set_global', |
||
63 | function () { |
||
64 | global $template, $conf; |
||
65 | $content = $template->assign( PIWIGO2MEDIAWIKI_DIR.'action.tpl' ); |
||
66 | $template->append('element_set_global_plugins_actions', |
||
67 | array( |
||
68 | 'ID' => PIWIGO2MEDIAWIKI_ID, |
||
69 | 'NAME' => l10n('Copy to MediaWiki'), 'CONTENT' => $content, |
||
70 | ) |
||
71 | ); |
||
72 | } |
||
73 | ); |
||
74 | |||
75 | } |
||
76 |
PHP has two types of connecting operators (logical operators, and boolean operators):
and
&&
or
||
The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&
, or||
.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
die
introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrow
at this point:These limitations lead to logical operators rarely being of use in current PHP code.