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
09201358
Commit
09201358
authored
May 12, 2014
by
Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract favorites processing logic to functions
parent
1fc64caf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
125 additions
and
71 deletions
+125
-71
qa-app-favorites.php
qa-include/qa-app-favorites.php
+116
-0
qa-page-favorites.php
qa-include/qa-page-favorites.php
+9
-71
No files found.
qa-include/qa-app-favorites.php
View file @
09201358
...
...
@@ -75,6 +75,121 @@
}
function
qa_favorite_q_list_view
(
$questions
,
$usershtml
)
/*
Returns content to set in $qa_content['q_list'] for a user's favorite $questions. Pre-generated
user HTML in $usershtml.
*/
{
$q_list
=
array
(
'qs'
=>
array
(),
);
if
(
count
(
$questions
)
===
0
)
return
$q_list
;
$q_list
[
'form'
]
=
array
(
'tags'
=>
'method="post" action="'
.
qa_self_html
()
.
'"'
,
'hidden'
=>
array
(
'code'
=>
qa_get_form_security_code
(
'vote'
),
),
);
$defaults
=
qa_post_html_defaults
(
'Q'
);
foreach
(
$questions
as
$question
)
{
$q_list
[
'qs'
][]
=
qa_post_html_fields
(
$question
,
qa_get_logged_in_userid
(),
qa_cookie_get
(),
$usershtml
,
null
,
qa_post_html_options
(
$question
,
$defaults
));
}
return
$q_list
;
}
function
qa_favorite_users_view
(
$users
,
$usershtml
)
/*
Returns content to set in $qa_content['ranking_users'] for a user's favorite $users. Pre-generated
user HTML in $usershtml.
*/
{
if
(
QA_FINAL_EXTERNAL_USERS
)
return
null
;
require_once
QA_INCLUDE_DIR
.
'qa-app-users.php'
;
$ranking
=
array
(
'items'
=>
array
(),
'rows'
=>
ceil
(
count
(
$users
)
/
qa_opt
(
'columns_users'
)),
'type'
=>
'users'
,
);
foreach
(
$users
as
$user
)
{
$avatarhtml
=
qa_get_user_avatar_html
(
$user
[
'flags'
],
$user
[
'email'
],
$user
[
'handle'
],
$user
[
'avatarblobid'
],
$user
[
'avatarwidth'
],
$user
[
'avatarheight'
],
qa_opt
(
'avatar_users_size'
),
true
);
$ranking
[
'items'
][]
=
array
(
'avatar'
=>
$avatarhtml
,
'label'
=>
$usershtml
[
$user
[
'userid'
]],
'score'
=>
qa_html
(
number_format
(
$user
[
'points'
])),
'raw'
=>
$user
,
);
}
return
$ranking
;
}
function
qa_favorite_tags_view
(
$tags
)
/*
Returns content to set in $qa_content['ranking_tagss'] for a user's favorite $tags.
*/
{
$ranking
=
array
(
'items'
=>
array
(),
'rows'
=>
ceil
(
count
(
$tags
)
/
qa_opt
(
'columns_tags'
)),
'type'
=>
'tags'
);
foreach
(
$tags
as
$tag
)
{
$ranking
[
'items'
][]
=
array
(
'label'
=>
qa_tag_html
(
$tag
[
'word'
],
false
,
true
),
'count'
=>
number_format
(
$tag
[
'tagcount'
]),
);
}
return
$ranking
;
}
function
qa_favorite_categories_view
(
$categories
)
/*
Returns content to set in $qa_content['nav_list_categories'] for a user's favorite $categories.
*/
{
$nav_list_categories
=
array
(
'nav'
=>
array
(),
'type'
=>
'browse-cat'
,
);
foreach
(
$categories
as
$category
)
{
$cat_url
=
qa_path_html
(
'questions/'
.
implode
(
'/'
,
array_reverse
(
explode
(
'/'
,
$category
[
'backpath'
]))
)
);
$cat_anchor
=
$category
[
'qcount'
]
==
1
?
qa_lang_html_sub
(
'main/1_question'
,
'1'
,
'1'
)
:
qa_lang_html_sub
(
'main/x_questions'
,
number_format
(
$category
[
'qcount'
]));
$cat_descr
=
strlen
(
$category
[
'content'
])
?
qa_html
(
' - '
.
$category
[
'content'
])
:
''
;
$nav_list_categories
[
'nav'
][
$category
[
'categoryid'
]]
=
array
(
'label'
=>
qa_html
(
$category
[
'title'
]),
'state'
=>
'open'
,
'favorited'
=>
true
,
'note'
=>
' - <a href="'
.
$cat_url
.
'">'
.
$cat_anchor
.
'</a>'
.
$cat_descr
,
);
}
return
$nav_list_categories
;
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
qa-include/qa-page-favorites.php
View file @
09201358
...
...
@@ -31,6 +31,7 @@
require_once
QA_INCLUDE_DIR
.
'qa-db-selects.php'
;
require_once
QA_INCLUDE_DIR
.
'qa-app-format.php'
;
require_once
QA_INCLUDE_DIR
.
'qa-app-favorites.php'
;
// Check that we're logged in
...
...
@@ -62,94 +63,31 @@
// Favorite questions
$qa_content
[
'q_list'
]
=
array
(
'title'
=>
count
(
$questions
)
?
qa_lang_html
(
'main/nav_qs'
)
:
qa_lang_html
(
'misc/no_favorite_qs'
),
'qs'
=>
array
(),
);
if
(
count
(
$questions
))
{
$qa_content
[
'q_list'
][
'form'
]
=
array
(
'tags'
=>
'method="post" action="'
.
qa_self_html
()
.
'"'
,
'hidden'
=>
array
(
'code'
=>
qa_get_form_security_code
(
'vote'
),
),
);
$defaults
=
qa_post_html_defaults
(
'Q'
);
foreach
(
$questions
as
$question
)
{
$qa_content
[
'q_list'
][
'qs'
][]
=
qa_post_html_fields
(
$question
,
$userid
,
qa_cookie_get
(),
$usershtml
,
null
,
qa_post_html_options
(
$question
,
$defaults
));
}
}
$qa_content
[
'q_list'
]
=
qa_favorite_q_list_view
(
$questions
,
$usershtml
);
$qa_content
[
'q_list'
][
'title'
]
=
count
(
$questions
)
?
qa_lang_html
(
'main/nav_qs'
)
:
qa_lang_html
(
'misc/no_favorite_qs'
);
// Favorite users
if
(
!
QA_FINAL_EXTERNAL_USERS
)
{
$qa_content
[
'ranking_users'
]
=
array
(
'title'
=>
count
(
$users
)
?
qa_lang_html
(
'main/nav_users'
)
:
qa_lang_html
(
'misc/no_favorite_users'
),
'items'
=>
array
(),
'rows'
=>
ceil
(
count
(
$users
)
/
qa_opt
(
'columns_users'
)),
'type'
=>
'users'
);
foreach
(
$users
as
$user
)
{
$avatarhtml
=
qa_get_user_avatar_html
(
$user
[
'flags'
],
$user
[
'email'
],
$user
[
'handle'
],
$user
[
'avatarblobid'
],
$user
[
'avatarwidth'
],
$user
[
'avatarheight'
],
qa_opt
(
'avatar_users_size'
),
true
);
$qa_content
[
'ranking_users'
][
'items'
][]
=
array
(
'avatar'
=>
$avatarhtml
,
'label'
=>
$usershtml
[
$user
[
'userid'
]],
'score'
=>
qa_html
(
number_format
(
$user
[
'points'
])),
'raw'
=>
$user
,
);
}
$qa_content
[
'ranking_users'
]
=
qa_favorite_users_view
(
$users
,
$usershtml
);
$qa_content
[
'ranking_users'
][
'title'
]
=
count
(
$users
)
?
qa_lang_html
(
'main/nav_users'
)
:
qa_lang_html
(
'misc/no_favorite_users'
);
}
// Favorite tags
if
(
qa_using_tags
())
{
$qa_content
[
'ranking_tags'
]
=
array
(
'title'
=>
count
(
$tags
)
?
qa_lang_html
(
'main/nav_tags'
)
:
qa_lang_html
(
'misc/no_favorite_tags'
),
'items'
=>
array
(),
'rows'
=>
ceil
(
count
(
$tags
)
/
qa_opt
(
'columns_tags'
)),
'type'
=>
'tags'
);
foreach
(
$tags
as
$tag
)
{
$qa_content
[
'ranking_tags'
][
'items'
][]
=
array
(
'label'
=>
qa_tag_html
(
$tag
[
'word'
],
false
,
true
),
'count'
=>
number_format
(
$tag
[
'tagcount'
]),
);
}
$qa_content
[
'ranking_tags'
]
=
qa_favorite_tags_view
(
$tags
);
$qa_content
[
'ranking_tags'
][
'title'
]
=
count
(
$tags
)
?
qa_lang_html
(
'main/nav_tags'
)
:
qa_lang_html
(
'misc/no_favorite_tags'
);
}
// Favorite categories
if
(
qa_using_categories
())
{
$qa_content
[
'nav_list_categories'
]
=
array
(
'title'
=>
count
(
$categories
)
?
qa_lang_html
(
'main/nav_categories'
)
:
qa_lang_html
(
'misc/no_favorite_categories'
),
'nav'
=>
array
(),
'type'
=>
'browse-cat'
,
);
foreach
(
$categories
as
$category
)
{
$cat_url
=
qa_path_html
(
'questions/'
.
implode
(
'/'
,
array_reverse
(
explode
(
'/'
,
$category
[
'backpath'
]))
)
);
$cat_anchor
=
$category
[
'qcount'
]
==
1
?
qa_lang_html_sub
(
'main/1_question'
,
'1'
,
'1'
)
:
qa_lang_html_sub
(
'main/x_questions'
,
number_format
(
$category
[
'qcount'
]));
$cat_descr
=
strlen
(
$category
[
'content'
])
?
qa_html
(
' - '
.
$category
[
'content'
])
:
''
;
$qa_content
[
'nav_list_categories'
][
'nav'
][
$category
[
'categoryid'
]]
=
array
(
'label'
=>
qa_html
(
$category
[
'title'
]),
'state'
=>
'open'
,
'favorited'
=>
true
,
'note'
=>
' - <a href="'
.
$cat_url
.
'">'
.
$cat_anchor
.
'</a>'
.
$cat_descr
,
);
}
$qa_content
[
'nav_list_categories'
]
=
qa_favorite_categories_view
(
$categories
);
$qa_content
[
'nav_list_categories'
][
'title'
]
=
count
(
$categories
)
?
qa_lang_html
(
'main/nav_categories'
)
:
qa_lang_html
(
'misc/no_favorite_categories'
);
}
...
...
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