/wp-content/plugins/anthologize/includes/theming-functions.php

https://github.com/livinglab/openlab · PHP · 602 lines · 407 code · 152 blank · 43 comment · 35 complexity · 05ae7e03f604c515965a33fda3ff4609 MD5 · raw file

  1. <?php
  2. //fire up some globals to use.
  3. global $section;
  4. global $partN;
  5. global $partCount;
  6. global $itemN;
  7. global $itemCount;
  8. $section = false;
  9. $partN = -1;
  10. $partCount = false;
  11. $itemN = -1;
  12. $itemCount = false;
  13. /**
  14. * echo the project title
  15. */
  16. function anth_the_project_title($valueOnly = false) {
  17. echo anth_get_the_project_title($valueOnly);
  18. }
  19. function anth_get_the_project_title($valueOnly = false) {
  20. global $api;
  21. return $api->getProjectTitle($valueOnly);
  22. }
  23. /**
  24. * echo the project subtitle
  25. */
  26. function anth_the_project_subtitle($valueOnly = false) {
  27. echo anth_get_the_project_subtitle($valueOnly);
  28. }
  29. function anth_get_the_project_subtitle($valueOnly = false) {
  30. global $api;
  31. return $api->getProjectSubTitle();
  32. }
  33. /**
  34. * set the section to loop through ('front', 'body', or 'back') and prepare to loop through parts
  35. */
  36. function anth_section($section_name) {
  37. global $api;
  38. global $section;
  39. global $partCount;
  40. $section = $section_name;
  41. switch($section_name) {
  42. case 'front':
  43. $partCount = 1;
  44. break;
  45. case 'body':
  46. $partCount = $api->getSectionPartCount($section);
  47. break;
  48. case 'back':
  49. $partCount = 1;
  50. break;
  51. }
  52. }
  53. /**
  54. * loop through the parts of the current section
  55. * like while( anth_parts() { output } )
  56. */
  57. function anth_parts() {
  58. global $partN;
  59. global $partCount;
  60. if ($partN < $partCount - 1) {
  61. return true;
  62. }
  63. $partCount = false;
  64. $partN = -1;
  65. return false;
  66. }
  67. /**
  68. * step through to the next part of the section to theme the output
  69. */
  70. function anth_part() {
  71. global $api;
  72. global $section;
  73. global $partN;
  74. global $partCount;
  75. global $itemCount;
  76. $partN++;
  77. $itemCount = $api->getSectionPartItemCount($section, $partN);
  78. }
  79. /**
  80. * check whether there are any items in the part
  81. */
  82. function anth_part_has_items() {
  83. global $itemCount;
  84. return false !== $itemCount;
  85. }
  86. /**
  87. * loop through the items in a part
  88. * like while(anth_part_items() { output } )
  89. */
  90. function anth_part_items() {
  91. global $itemN;
  92. global $itemCount;
  93. if ($itemN < $itemCount - 1 ) {
  94. return true;
  95. }
  96. $itemCount = false;
  97. $itemN = -1;
  98. return false;
  99. }
  100. /**
  101. * step to the next item for theming
  102. */
  103. function anth_item() {
  104. global $itemN;
  105. $itemN++;
  106. }
  107. /**
  108. * echo the title of the current thing. If in an item, the item's title, if only to part level, the part title'
  109. */
  110. function anth_the_title() {
  111. echo anth_get_the_title();
  112. }
  113. function anth_get_the_title() {
  114. global $api;
  115. global $section;
  116. global $partN;
  117. global $partCount;
  118. global $itemCount;
  119. global $itemN;
  120. if($itemN != -1) {
  121. return $api->getSectionPartItemTitle($section, $partN, $itemN);
  122. }
  123. if($partN != -1) {
  124. return $api->getSectionPartTitle($section, $partN);
  125. }
  126. return false;
  127. }
  128. /**
  129. * echo the author of the item, or part
  130. */
  131. function anth_the_person($role = 'author') {
  132. echo anth_get_the_person($role);
  133. }
  134. function anth_get_the_person($role = 'author') {
  135. global $api;
  136. global $section;
  137. global $partN;
  138. global $partCount;
  139. global $itemCount;
  140. global $itemN;
  141. if(false !== $itemCount) {
  142. switch ($role) {
  143. case 'author':
  144. return $api->getSectionPartItemOriginalAuthor($section, $partN, $itemN);
  145. break;
  146. case 'anthologizer':
  147. return $api->getSectionPartItemAnthologizer($section, $partN, $itemN);
  148. break;
  149. case 'assertedAuthor':
  150. $author = $api->getSectionPartItemAssertedAuthor($section, $partN, $itemN);
  151. if($author && ($author != '')) {
  152. return $author;
  153. }
  154. break;
  155. }
  156. }
  157. return false;
  158. }
  159. /**
  160. * item content
  161. */
  162. function anth_get_the_item_content() {
  163. global $api;
  164. global $section;
  165. global $partN;
  166. global $partCount;
  167. global $itemCount;
  168. global $itemN;
  169. if(false !== $itemN) {
  170. return $api->getSectionPartItemContent($section, $partN, $itemN);
  171. }
  172. return false;
  173. }
  174. function anth_the_item_content() {
  175. echo anth_get_the_item_content();
  176. }
  177. /* Functions requiring structured author information */
  178. function anth_the_person_gravatar_url($role = 'author') {
  179. echo anth_get_the_person_gravatar_url();
  180. }
  181. function anth_get_the_person_gravatar_url($role = 'author') {
  182. return anth_get_the_person_detail('gravatarUrl', $role);
  183. }
  184. function anth_person_details($role = 'author') {
  185. global $api;
  186. global $section;
  187. global $partN;
  188. global $partCount;
  189. global $itemCount;
  190. global $itemN;
  191. global $person_details;
  192. if(false !== $itemCount) {
  193. switch ($role) {
  194. case 'author':
  195. $person = $api->getSectionPartItemOriginalAuthor($section, $partN, $itemN, false, false);
  196. break;
  197. case 'anthologizer':
  198. $person = $api->getSectionPartItemAnthologizer($section, $partN, $itemN, false, false);
  199. break;
  200. case 'assertedAuthor':
  201. $person = $api->getSectionPartItemAssertedAuthor($section, $partN, $itemN, false, false);
  202. break;
  203. }
  204. }
  205. if ( ! $person ) {
  206. return;
  207. }
  208. $person_details = $api->getDetailsByRef($person['atts']['ref']);
  209. }
  210. function anth_get_the_person_detail($detail, $role = 'author') {
  211. global $api;
  212. global $section;
  213. global $partN;
  214. global $partCount;
  215. global $itemCount;
  216. global $itemN;
  217. global $person_details;
  218. if(! isset($person_details)) {
  219. if(false !== $itemCount) {
  220. $person = anth_get_the_person($role);
  221. }
  222. $person_details = $api->getDetailsByRef($person['atts']['ref']);
  223. }
  224. return $api->getPersonDetail($person_details, $detail);
  225. }
  226. /* Functions requiring structured content information */
  227. /* Functions requiring subject data */
  228. function anth_tags() {
  229. global $api;
  230. global $section;
  231. global $partN;
  232. global $partCount;
  233. global $itemCount;
  234. global $itemN;
  235. global $tags;
  236. global $tagIndex;
  237. if(! is_array($tags) ) {
  238. $tags = $api->getSectionPartItemTags($section, $partN, $itemN);
  239. $tagIndex = -1;
  240. }
  241. if($tags) {
  242. $tagIndex++;
  243. if($tagIndex >= count($tags)) {
  244. unset($tags);
  245. $tagIndex = -1;
  246. return false;
  247. } else {
  248. return true;
  249. }
  250. }
  251. }
  252. /**
  253. * sets the deep data array for the tag. access details via anth_tag_detail($detail)
  254. */
  255. function anth_tag_details() {
  256. global $api;
  257. global $section;
  258. global $partN;
  259. global $partCount;
  260. global $itemCount;
  261. global $itemN;
  262. global $tags;
  263. global $tagIndex;
  264. global $tag_details;
  265. if(is_array($tags) && isset($tags[$tagIndex] ) ) {
  266. $ref = $tags[$tagIndex]['atts']['ref'];
  267. $tag_details = $api->getDetailsByRef($ref);
  268. }
  269. }
  270. function anth_get_the_tag() {
  271. global $api;
  272. global $section;
  273. global $partN;
  274. global $partCount;
  275. global $itemCount;
  276. global $itemN;
  277. global $tags;
  278. global $tagIndex;
  279. return $tags[$tagIndex]['spans'][0]['value'];
  280. }
  281. function anth_the_tag() {
  282. echo anth_get_the_tag();
  283. }
  284. function anth_get_the_tag_detail($detail) {
  285. global $tag_details;
  286. switch($detail) {
  287. case 'count':
  288. $retValue = $tag_details['nums'][0]['value'];
  289. break;
  290. case 'description':
  291. $retValue = $tag_details['descs'][0]['divs'][0]['value'];
  292. break;
  293. case 'url':
  294. $retValue = $tag_details['idents'][0]['value'];
  295. break;
  296. }
  297. return $retValue;
  298. }
  299. function anth_the_tag_detail($detail) {
  300. echo anth_get_the_tag_detail($detail);
  301. }
  302. function anth_categories() {
  303. global $api;
  304. global $section;
  305. global $partN;
  306. global $partCount;
  307. global $itemCount;
  308. global $itemN;
  309. global $categories;
  310. global $catIndex;
  311. if(! is_array($categories) ) {
  312. $categories = $api->getSectionPartItemCategories($section, $partN, $itemN);
  313. $catIndex = -1;
  314. }
  315. if($categories) {
  316. $catIndex++;
  317. if($catIndex >= count($categories)) {
  318. unset($categories);
  319. $catIndex = -1;
  320. return false;
  321. } else {
  322. return true;
  323. }
  324. }
  325. }
  326. function anth_category_details() {
  327. global $api;
  328. global $section;
  329. global $partN;
  330. global $partCount;
  331. global $itemCount;
  332. global $itemN;
  333. global $categories;
  334. global $catIndex;
  335. global $cat_details;
  336. if(is_array($categories) && isset($categories[$catIndex] ) ) {
  337. $ref = $categories[$catIndex]['atts']['ref'];
  338. $cat_details = $api->getDetailsByRef($ref);
  339. }
  340. }
  341. function anth_get_the_category() {
  342. global $api;
  343. global $section;
  344. global $partN;
  345. global $partCount;
  346. global $itemCount;
  347. global $itemN;
  348. global $categories;
  349. global $catIndex;
  350. return $categories[$catIndex]['spans'][0]['value'];
  351. }
  352. function anth_the_category() {
  353. echo anth_get_the_category();
  354. }
  355. function anth_get_the_category_detail($detail) {
  356. global $cat_details;
  357. switch($detail) {
  358. case 'count':
  359. $retValue = $cat_details['nums'][0]['value'];
  360. break;
  361. case 'description':
  362. $retValue = $cat_details['descs'][0]['divs'][0]['value'];
  363. break;
  364. case 'url':
  365. $retValue = $cat_details['idents'][0]['value'];
  366. break;
  367. }
  368. return $retValue;
  369. }
  370. function anth_the_category_detail($detail) {
  371. echo anth_get_the_category_detail($detail);
  372. }
  373. /* Indexing functions */
  374. function anth_index($name) {
  375. global $api;
  376. global $index;
  377. global $indexItemIndex;
  378. $indexIndex = -1;
  379. $index = $api->getIndex($name);
  380. }
  381. function anth_index_items() {
  382. global $api;
  383. global $index;
  384. global $indexItemIndex;
  385. if($index) {
  386. $indexItemIndex++;
  387. if($indexItemIndex >= $api->getIndexItemCount($index)) {
  388. unset($index);
  389. $IndexItemIndex = -1;
  390. return false;
  391. } else {
  392. return true;
  393. }
  394. }
  395. }
  396. function anth_index_item() {
  397. global $api;
  398. global $index;
  399. global $indexItemIndex;
  400. global $indexItem;
  401. global $indexItemTargetIndex;
  402. $indexItemTargetIndex = -1;
  403. $indexItem = $api->getIndexItem($index, $indexItemIndex);
  404. }
  405. function anth_index_get_the_item_label() {
  406. global $api;
  407. global $indexItem;
  408. return $api->getIndexItemLabel($indexItem);
  409. }
  410. function anth_index_the_item_label() {
  411. global $api;
  412. global $indexItem;
  413. echo anth_index_get_the_item_label();
  414. }
  415. function anth_index_item_ref() {
  416. global $api;
  417. global $indexItem;
  418. global $indexItemRef;
  419. $indexItemRef = $api->getIndexItemRef($indexItem);
  420. }
  421. function anth_index_item_targets() {
  422. global $api;
  423. global $indexItem;
  424. global $indexItemTargetIndex;
  425. if($indexItem) {
  426. $indexItemTargetIndex++;
  427. if($indexItemTargetIndex >= $api->getIndexItemTargetCount($indexItem)) {
  428. unset($indexItem);
  429. $indexItemTargetIndex = -1;
  430. return false;
  431. } else {
  432. return true;
  433. }
  434. }
  435. }
  436. function anth_index_item_target() {
  437. global $api;
  438. global $indexItem;
  439. global $indexItemTarget;
  440. global $indexItemTargetIndex;
  441. $indexItemTarget = $api->getIndexItemTarget($indexItem, $indexItemTargetIndex);
  442. }
  443. function anth_index_item_get_the_target($detail = 'label') {
  444. global $api;
  445. global $indexItemTarget;
  446. return $api->getIndexItemTargetDetail($indexItemTarget, $detail);
  447. }
  448. function anth_index_item_the_target($detail = 'label') {
  449. echo anth_index_item_get_the_target($detail);
  450. }