PageRenderTime 57ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/core/gw_modules/mod_items.php

http://glossword.googlecode.com/
PHP | 285 lines | 227 code | 10 blank | 48 comment | 48 complexity | a84a35bc06b1cf187292e57ad84edad4 MD5 | raw file
  1. <?php
  2. /* The common functions for $target */
  3. class gw_mod_items extends site_prepend
  4. {
  5. public $parse__is_preview = 1;
  6. /* */
  7. public function autoexec()
  8. {
  9. if ( $this->gv['sef_output'] != 'js' && $this->gv['sef_output'] != 'css' && $this->gv['sef_output'] != 'ajax' )
  10. {
  11. $this->oTpl->assign( 'v:h_tabs', '<div class="gw-actions">'.implode(' ', $this->get_actions() ).'</div>' );
  12. }
  13. }
  14. /* */
  15. public function get_statuses()
  16. {
  17. return array(
  18. GW_STATUS_OFF => $this->oTkit->_( 1070 ),
  19. GW_STATUS_ON => $this->oTkit->_( 1069 ),
  20. GW_STATUS_PENDING => $this->oTkit->_( 1071 ),
  21. GW_STATUS_REMOVE => $this->oTkit->_( 1073 )
  22. );
  23. }
  24. /* */
  25. public function get_statuses_classnames()
  26. {
  27. return array(
  28. GW_STATUS_OFF => 'state-warning',
  29. GW_STATUS_ON => 'state-allow',
  30. GW_STATUS_PENDING => 'state-wait',
  31. GW_STATUS_REMOVE => 'state-warning'
  32. );
  33. }
  34. /* */
  35. public function get_actions()
  36. {
  37. $oHref = $this->oHtmlAdm->oHref();
  38. $oHref->set( 't', $this->gv['target'] );
  39. $ar_ctrl = array();
  40. if ( $this->oSess->is( 'items-own' ) || $this->oSess->is( 'items' ) )
  41. {
  42. $oHref->set( 'a', 'add' );
  43. $ar_ctrl[] = $this->oHtmlAdm->a_href(
  44. array( $this->V->file_index, '#area' => $oHref->get() ),
  45. array( 'title' => $this->oTkit->_( 1001 ).': '.$this->oTkit->_( 1003 ) ),
  46. $this->oTkit->_( 1001 )
  47. );
  48. $oHref->set( 'a', 'manage' );
  49. $ar_ctrl[] = $this->oHtmlAdm->a_href(
  50. array( $this->V->file_index, '#area' => $oHref->get() ),
  51. array( 'title' => $this->oTkit->_( 1006 ).': '.$this->oTkit->_( 1003 ) ),
  52. $this->oTkit->_( 1006 )
  53. );
  54. $oHref->set( 'a', 'import' );
  55. $ar_ctrl[] = $this->oHtmlAdm->a_href(
  56. array( $this->V->file_index, '#area' => $oHref->get() ),
  57. array( 'title' => $this->oTkit->_( 1077 ).': '.$this->oTkit->_( 1003 ) ),
  58. $this->oTkit->_( 1077 )
  59. );
  60. $oHref->set( 'a', 'export' );
  61. $ar_ctrl[] = $this->oHtmlAdm->a_href(
  62. array( $this->V->file_index, '#area' => $oHref->get() ),
  63. array( 'title' => $this->oTkit->_( 1079 ).': '.$this->oTkit->_( 1003 ) ),
  64. $this->oTkit->_( 1079 )
  65. );
  66. }
  67. return $ar_ctrl;
  68. }
  69. /* */
  70. public function parse_ar_item( $ar_item )
  71. {
  72. /*
  73. $ar_item[$ar_v['id_field']][$ar_v['id_contents']] = $ar_v;
  74. [id_field1]
  75. [id_contents1]
  76. [contents_value_cached1]
  77. [id_field2]
  78. [id_contents2]
  79. [contents_value_cached2]
  80. [id_contents3]
  81. [contents_value_cached3]
  82. -----------
  83. [id_field1]
  84. [contents_value_cached1]
  85. [id_field2]
  86. [contents_value_cached2] [contents_value_cached3]
  87. */
  88. $str_item = $str_item_cut = $str_item_url = $str_descr = $str_descr_cut = $contents_a = '';
  89. $ar_defn_complete = $ar_item_settings = array();
  90. $str_is_complete_single = '';
  91. foreach ( $ar_item as $id_field => $ar_content)
  92. {
  93. $str_is_complete = '';
  94. $ar_str_field = array();
  95. $fields_separator = ' รข&#x2014;&#x160; ';
  96. foreach ( $ar_content as $id_contents => $ar_v)
  97. {
  98. if ( $this->V->id_field_root == $id_field )
  99. {
  100. if ( !$ar_v['is_complete'] )
  101. {
  102. $str_is_complete = $str_is_complete_single = '<strong>?</strong> ';
  103. }
  104. $ar_item_settings = $ar_v;
  105. $contents_a = $ar_v['contents_a'];
  106. }
  107. /* */
  108. switch ( $id_field )
  109. {
  110. case 2: /** Definition **/
  111. $ar_str_field[] = '<div>'.$ar_v['contents_value_cached'].'</div>';
  112. break;
  113. case 3: /** See Also **/
  114. if ( $ar_v['contents_value_cached'] != '' )
  115. {
  116. $oHref = $this->oHtml->oHref();
  117. $oHref->set( 't', 'items' );
  118. $oHref->set( 'a', 'search' );
  119. $oHref->set( 'q', $ar_v['contents_value_cached'] );
  120. $ar_str_field[] = $this->oHtml->a_href(
  121. array( $this->V->file_index, '#area' => $oHref->get() ),
  122. array( ), $ar_v['contents_value_cached']
  123. );
  124. }
  125. $fields_separator = ', ';
  126. break;
  127. default:
  128. $ar_str_field[] = $ar_v['contents_value_cached'];
  129. break;
  130. }
  131. }
  132. $str_field = implode( $fields_separator, $ar_str_field );
  133. if ( $this->parse__is_preview )
  134. {
  135. $str_field = implode( $fields_separator, $ar_str_field );
  136. }
  137. /* */
  138. if ( $this->V->id_field_root == $id_field )
  139. {
  140. /* At once */
  141. $str_item = $str_field;
  142. $str_item_cut = $this->oFunc->smart_substr( strip_tags( $str_item ), 0, 32 );
  143. /* View item */
  144. switch ( $this->V->link_mode )
  145. {
  146. case GW_LINK_ID: $item_uri = $ar_item_settings['id_item']; break;
  147. case GW_LINK_URI: $item_uri = $ar_item_settings['item_uri']; break;
  148. case GW_LINK_TEXT: $item_uri = $this->oHtml->urlencode( $str_item ); break;
  149. }
  150. /* */
  151. if ( $this->V->link_template_uri != '' && $this->V->link_mode != GW_LINK_ID )
  152. {
  153. $item_uri = str_replace( '%s', $item_uri, $this->V->link_template_uri );
  154. }
  155. /* Place link to item */
  156. $str_item_url = $this->oHtml->a_href( array( $this->V->file_index, '#area' => 'id.'.$item_uri ), array(), $str_item );
  157. if ( !$this->V->is_link_item
  158. && ( $this->V->int_max_chars_preview == "-1" || $this->V->int_max_chars_preview == "0" )
  159. )
  160. {
  161. $str_item_url = $str_item;
  162. }
  163. /* Edit item */
  164. $str_item_url_admin = '';
  165. if ( SITE_ADMIN_MODE
  166. || $this->oSess->is( 'items' )
  167. || ( $this->oSess->is( 'items-own' ) && $ar_item_settings['item_id_user_created'] == $this->oSess->id_user )
  168. )
  169. {
  170. $oHref = $this->oHtmlAdm->oHref();
  171. $oHref->set( 'a', 'edit' );
  172. $oHref->set( 't', 'items' );
  173. $oHref->set( 'id_item', $ar_v['id_item'] );
  174. if ( SITE_ADMIN_MODE )
  175. {
  176. /* Link to Edit Item */
  177. $str_item_url = $str_is_complete . $this->oHtmlAdm->a_href(
  178. array( $this->V->file_index, '#area' => $oHref->get(), '#uri' => base64_encode( $this->V->uri ) ),
  179. array( 'class' => 'btn edit' ), $str_item . $this->V->str_class_edit
  180. );
  181. }
  182. else
  183. {
  184. $str_item_url_admin = $this->oHtmlAdm->a_href(
  185. array( $this->V->file_index, '#area' => $oHref->get(), '#uri' => base64_encode( $this->V->uri ) ),
  186. array( 'class' => 'btn edit' ), $this->oTkit->_( 1042 ) . $this->V->str_class_edit
  187. );
  188. /* Link to Item and link to Edit Item onmouseover */
  189. $str_item_url = $str_is_complete . '<span class="hide-over">'. $str_item_url
  190. . ' <span class="hide-under">'. $str_item_url_admin. '</span></span>';
  191. }
  192. }
  193. }
  194. /* Collect fields for a common definition */
  195. switch ( $id_field )
  196. {
  197. /* Do not include Item into Definition text */
  198. case 1:
  199. break;
  200. case 3: /** See Also **/
  201. $ar_defn_complete[] = '<div><em>'.$this->oTkit->_( 1076 ) .':</em> ' . $str_field .'</div>';
  202. break;
  203. default:
  204. $ar_defn_complete[] = $str_field;
  205. break;
  206. }
  207. }
  208. $str_descr = implode( ' ', $ar_defn_complete );
  209. /* */
  210. if ( $this->parse__is_preview )
  211. {
  212. /* Add space for tags */
  213. $str_descr = str_replace( '><', '> <', $str_descr);
  214. /* Strip all tags from definition */
  215. $str_descr = strip_tags( $str_descr );
  216. }
  217. /* Smart substring */
  218. if ( $this->parse__is_preview && $this->oFunc->mb_strlen( $str_item ) > $this->V->int_max_chars_preview )
  219. {
  220. $str_item = $this->oFunc->smart_substr( $str_item, 0, $this->V->int_max_chars_preview );
  221. }
  222. if ( $this->parse__is_preview && $this->oFunc->mb_strlen( $str_descr ) > $this->V->int_max_chars_preview )
  223. {
  224. $str_descr = $this->oFunc->smart_substr( $str_descr, 0, $this->V->int_max_chars_preview );
  225. }
  226. $str_descr_cut = $this->oFunc->smart_substr( strip_tags( $str_descr ), 0, 32 );
  227. /* Do not link to an empty term */
  228. if ( SITE_WEB_MODE && $str_descr == '' )
  229. {
  230. /* Enable to edit not linked term */
  231. if ( $str_item_url_admin )
  232. {
  233. $str_item_url = '<span class="hide-over">'. $str_item .' <span class="hide-under">'. $str_item_url_admin .'</span></span>';
  234. }
  235. else
  236. {
  237. $str_item_url = $str_item;
  238. }
  239. }
  240. /* No preview */
  241. if ( $this->V->int_max_chars_preview == 0 )
  242. {
  243. $str_descr = '';
  244. }
  245. /* Complete / Incomplete Mark for a single term */
  246. $str_item = $str_is_complete_single . $str_item;
  247. /* Read user settings */
  248. $ar_item_settings['uc_user_displayed_name'] = $ar_item_settings['item_id_user_created'];
  249. if ( isset( $ar_item_settings['uc_user_settings'] ) )
  250. {
  251. $ar_item_settings['uc_user_settings'] = unserialize($ar_v['uc_user_settings']);
  252. /* Define displayed name */
  253. if ( !isset( $ar_item_settings['uc_user_settings']['displayed_name'] ) )
  254. {
  255. $ar_item_settings['uc_user_settings']['displayed_name'] = 2;
  256. }
  257. switch ( $ar_item_settings['uc_user_settings']['displayed_name'] )
  258. {
  259. case 1: $ar_item_settings['uc_user_displayed_name'] = $ar_v['uc_user_nickname']; break;
  260. case 2: $ar_item_settings['uc_user_displayed_name'] = $ar_v['uc_user_fname']; break;
  261. case 3: $ar_item_settings['uc_user_displayed_name'] = $ar_v['uc_user_sname']; break;
  262. case 4: $ar_item_settings['uc_user_displayed_name'] = $ar_v['uc_user_fname'].' '.$ar_v['uc_user_sname']; break;
  263. default: $ar_item_settings['uc_user_displayed_name'] = $ar_v['id_user']; break;
  264. }
  265. }
  266. $ar_item_settings['contents_a'] = $contents_a;
  267. /*
  268. New variables:
  269. $ar_item_settings, $str_item, $str_item_cut, $str_item_url, $str_descr, $str_descr_cut, $contents_a
  270. */
  271. return array( $ar_item_settings, $str_item, $str_item_cut, $str_item_url, $str_descr, $str_descr_cut );
  272. }
  273. }
  274. ?>