Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
question2answer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
outils
question2answer
Commits
3973ffd6
Commit
3973ffd6
authored
Mar 20, 2014
by
Scott Vivian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed addon metadata function, removed duplicate strings and optimised code
parent
dafef9a2
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
66 additions
and
56 deletions
+66
-56
qa-admin.js
qa-content/qa-admin.js
+3
-4
qa-ajax-version.php
qa-include/qa-ajax-version.php
+18
-22
qa-app-admin.php
qa-include/qa-app-admin.php
+4
-1
qa-base.php
qa-include/qa-base.php
+32
-0
qa-page-admin-default.php
qa-include/qa-page-admin-default.php
+5
-13
qa-page-admin-plugins.php
qa-include/qa-page-admin-plugins.php
+4
-16
No files found.
qa-content/qa-admin.js
View file @
3973ffd6
...
...
@@ -134,9 +134,9 @@ function qa_admin_click(target)
return
false
;
}
function
qa_version_check
(
uri
,
versionkey
,
version
,
urikey
,
elem
)
function
qa_version_check
(
uri
,
type
,
version
,
elem
)
{
var
params
=
{
uri
:
uri
,
versionkey
:
versionkey
,
version
:
version
,
urikey
:
urikey
};
var
params
=
{
uri
:
uri
,
type
:
type
,
version
:
version
};
qa_ajax_post
(
'version'
,
params
,
function
(
lines
)
{
...
...
@@ -144,4 +144,4 @@ function qa_version_check(uri, versionkey, version, urikey, elem)
document
.
getElementById
(
elem
).
innerHTML
=
lines
[
1
];
}
);
}
\ No newline at end of file
}
qa-include/qa-ajax-version.php
View file @
3973ffd6
...
...
@@ -27,46 +27,42 @@
require_once
QA_INCLUDE_DIR
.
'qa-app-admin.php'
;
$uri
=
qa_post_text
(
'uri'
);
$versionkey
=
qa_post_text
(
'versionkey'
);
$urikey
=
qa_post_text
(
'urikey'
);
$version
=
qa_post_text
(
'version'
);
$uri
=
qa_post_text
(
'uri'
);
$type
=
(
qa_post_text
(
'type'
)
===
'Theme'
?
'Theme'
:
'Plugin'
);
$version
=
qa_post_text
(
'version'
);
$metadata
=
qa_admin_addon_metadata
(
qa_retrieve_url
(
$uri
),
array
(
'version'
=>
$versionkey
,
'uri'
=>
$urikey
,
// these two elements are only present for plugins, not themes, so we can hard code them here
'min_q2a'
=>
'Plugin Minimum Question2Answer Version'
,
'min_php'
=>
'Plugin Minimum PHP Version'
,
));
$metadata
=
qa_addon_metadata
(
qa_retrieve_url
(
$uri
),
$type
);
if
(
strlen
(
@
$metadata
[
'version'
]))
{
if
(
strcmp
(
$metadata
[
'version'
],
$version
))
{
if
(
qa_qa_version_below
(
@
$metadata
[
'min_q2a'
]))
$response
=
strtr
(
qa_lang_html
(
'admin/version_requires_q2a'
),
array
(
if
(
qa_qa_version_below
(
@
$metadata
[
'min_q2a'
]))
{
$response
=
strtr
(
qa_lang_html
(
'admin/version_requires_q2a'
),
array
(
'^1'
=>
qa_html
(
'v'
.
$metadata
[
'version'
]),
'^2'
=>
qa_html
(
$metadata
[
'min_q2a'
]),
));
}
elseif
(
qa_php_version_below
(
@
$metadata
[
'min_php'
]))
$response
=
strtr
(
qa_lang_html
(
'admin/version_requires_php'
),
array
(
elseif
(
qa_php_version_below
(
@
$metadata
[
'min_php'
]))
{
$response
=
strtr
(
qa_lang_html
(
'admin/version_requires_php'
),
array
(
'^1'
=>
qa_html
(
'v'
.
$metadata
[
'version'
]),
'^2'
=>
qa_html
(
$metadata
[
'min_php'
]),
));
}
else
{
$response
=
qa_lang_html_sub
(
'admin/version_get_x'
,
qa_html
(
'v'
.
$metadata
[
'version'
]));
$response
=
qa_lang_html_sub
(
'admin/version_get_x'
,
qa_html
(
'v'
.
$metadata
[
'version'
]));
if
(
strlen
(
@
$metadata
[
'uri'
]))
$response
=
'<a href="'
.
qa_html
(
$metadata
[
'uri'
])
.
'" style="color:#d00;">'
.
$response
.
'</a>'
;
$response
=
'<a href="'
.
qa_html
(
$metadata
[
'uri'
])
.
'" style="color:#d00;">'
.
$response
.
'</a>'
;
}
}
else
$response
=
qa_lang_html
(
'admin/version_latest'
);
}
else
$response
=
qa_lang_html
(
'admin/version_latest'
);
}
else
$response
=
qa_lang_html
(
'admin/version_latest_unknown'
);
}
else
$response
=
qa_lang_html
(
'admin/version_latest_unknown'
);
echo
"QA_AJAX_RESPONSE
\n
1
\n
"
.
$response
;
...
...
qa-include/qa-app-admin.php
View file @
3973ffd6
...
...
@@ -576,9 +576,12 @@
function
qa_admin_addon_metadata
(
$contents
,
$fields
)
/*
Retrieve metadata information from the $contents of a qa-theme.php or qa-plugin.php file, mapping via $fields
Retrieve metadata information from the $contents of a qa-theme.php or qa-plugin.php file, mapping via $fields.
This function is now DEPRECATED.
*/
{
trigger_error
(
'Function qa_admin_addon_metadata is deprecated; use qa_addon_metadata instead'
,
E_USER_NOTICE
);
$metadata
=
array
();
foreach
(
$fields
as
$key
=>
$field
)
...
...
qa-include/qa-base.php
View file @
3973ffd6
...
...
@@ -272,6 +272,38 @@
}
function
qa_addon_metadata
(
$contents
,
$type
)
/*
Retrieve metadata information from the $contents of a qa-theme.php or qa-plugin.php file, specified by $type ('Plugin' or 'Theme').
Name, Description, Min Q2A & Min PHP are not currently used by themes.
*/
{
$fields
=
array
(
'name'
=>
'Name'
,
'uri'
=>
'URI'
,
'description'
=>
'Description'
,
'version'
=>
'Version'
,
'date'
=>
'Date'
,
'author'
=>
'Author'
,
'author_uri'
=>
'Author URI'
,
'license'
=>
'License'
,
'min_q2a'
=>
'Minimum Question2Answer Version'
,
'min_php'
=>
'Minimum PHP Version'
,
'update'
=>
'Update Check URI'
,
);
$metadata
=
array
();
foreach
(
$fields
as
$key
=>
$field
)
{
// prepend 'Theme'/'Plugin' and search for key data
$fieldregex
=
str_replace
(
' '
,
'[ \t]*'
,
preg_quote
(
"
$type
$field
"
,
'/'
));
if
(
preg_match
(
'/'
.
$fieldregex
.
':[ \t]*([^\n\f]*)[\n\f]/i'
,
$contents
,
$matches
))
$metadata
[
$key
]
=
trim
(
$matches
[
1
]);
}
return
$metadata
;
}
function
qa_load_plugin_files
()
/*
Load all the qa-plugin.php files from plugins that are compatible with this version of Q2A
...
...
qa-include/qa-page-admin-default.php
View file @
3973ffd6
...
...
@@ -985,21 +985,13 @@
case
'site_theme_mobile'
:
$themeoptions
=
qa_admin_theme_options
();
if
(
!
isset
(
$themeoptions
[
$value
]))
$value
=
'Classic'
;
// check here because we also need $value for qa_ad
min_ad
don_metadata()
$value
=
'Classic'
;
// check here because we also need $value for qa_addon_metadata()
qa_optionfield_make_select
(
$optionfield
,
$themeoptions
,
$value
,
'Classic'
);
$contents
=
file_get_contents
(
QA_THEME_DIR
.
$value
.
'/qa-styles.css'
);
$metadata
=
qa_admin_addon_metadata
(
$contents
,
array
(
'uri'
=>
'Theme URI'
,
'version'
=>
'Theme Version'
,
'date'
=>
'Theme Date'
,
'author'
=>
'Theme Author'
,
'author_uri'
=>
'Theme Author URI'
,
'license'
=>
'Theme License'
,
'update'
=>
'Theme Update Check URI'
,
));
// limit theme parsing to first 8kB
$contents
=
file_get_contents
(
QA_THEME_DIR
.
$value
.
'/qa-styles.css'
,
false
,
NULL
,
-
1
,
8192
);
$metadata
=
qa_addon_metadata
(
$contents
,
'Theme'
);
if
(
strlen
(
@
$metadata
[
'version'
]))
$namehtml
=
'v'
.
qa_html
(
$metadata
[
'version'
]);
...
...
@@ -1030,7 +1022,7 @@
$updatehtml
=
'(<span id="'
.
$elementid
.
'">...</span>)'
;
$qa_content
[
'script_onloads'
][]
=
array
(
"qa_version_check("
.
qa_js
(
$metadata
[
'update'
])
.
", 'Theme
Version', "
.
qa_js
(
$metadata
[
'version'
],
true
)
.
", 'Theme URI'
, "
.
qa_js
(
$elementid
)
.
");"
"qa_version_check("
.
qa_js
(
$metadata
[
'update'
])
.
", 'Theme
', "
.
qa_js
(
$metadata
[
'version'
],
true
)
.
"
, "
.
qa_js
(
$elementid
)
.
");"
);
}
else
...
...
qa-include/qa-page-admin-plugins.php
View file @
3973ffd6
...
...
@@ -107,21 +107,9 @@
$hash
=
qa_admin_plugin_directory_hash
(
$plugindirectory
);
$showthisform
=
$showpluginforms
&&
(
qa_get
(
'show'
)
==
$hash
);
$contents
=
file_get_contents
(
$pluginfile
);
$metadata
=
qa_admin_addon_metadata
(
$contents
,
array
(
'name'
=>
'Plugin Name'
,
'uri'
=>
'Plugin URI'
,
'description'
=>
'Plugin Description'
,
'version'
=>
'Plugin Version'
,
'date'
=>
'Plugin Date'
,
'author'
=>
'Plugin Author'
,
'author_uri'
=>
'Plugin Author URI'
,
'license'
=>
'Plugin License'
,
'min_q2a'
=>
'Plugin Minimum Question2Answer Version'
,
'min_php'
=>
'Plugin Minimum PHP Version'
,
'update'
=>
'Plugin Update Check URI'
,
));
// limit plugin parsing to first 8kB
$contents
=
file_get_contents
(
$pluginfile
,
false
,
NULL
,
-
1
,
8192
);
$metadata
=
qa_addon_metadata
(
$contents
,
'Plugin'
);
if
(
strlen
(
@
$metadata
[
'name'
]))
$namehtml
=
qa_html
(
$metadata
[
'name'
]);
...
...
@@ -153,7 +141,7 @@
$updatehtml
=
'(<span id="'
.
$elementid
.
'">...</span>)'
;
$qa_content
[
'script_onloads'
][]
=
array
(
"qa_version_check("
.
qa_js
(
$metadata
[
'update'
])
.
", 'Plugin
Version', "
.
qa_js
(
$metadata
[
'version'
],
true
)
.
", 'Plugin URI'
, "
.
qa_js
(
$elementid
)
.
");"
"qa_version_check("
.
qa_js
(
$metadata
[
'update'
])
.
", 'Plugin
', "
.
qa_js
(
$metadata
[
'version'
],
true
)
.
"
, "
.
qa_js
(
$elementid
)
.
");"
);
}
else
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment