Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.88 KB | None | 0 0
  1. <?php
  2. /**
  3. * @package Related News
  4. * @version 2.5
  5. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
  6. * @copyright (c) 2012 YouTech Company. All Rights Reserved.
  7. * @author YouTech Company http://www.smartaddons.com
  8. *
  9. */
  10. defined('_JEXEC') or die;
  11.  
  12. $com_path = JPATH_SITE.'/components/com_content/';
  13. require_once $com_path.'router.php';
  14. require_once $com_path.'helpers/route.php';
  15. JModelLegacy::addIncludePath($com_path . '/models', 'ContentModel');
  16.  
  17. include_once dirname(__FILE__).'/helper_base.php';
  18.  
  19. class RelatedNews extends BaseHelper{
  20.  
  21. public static function getList(&$_params)
  22. {
  23. $db = JFactory::getDbo();
  24. // Get an instance of the generic articles model
  25. $articles = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
  26. // Set application parameters in model
  27.  
  28. $articles->setState(
  29. 'list.select',
  30. 'a.id, a.title, a.alias, a.introtext, a.fulltext, ' .
  31. 'a.checked_out, a.checked_out_time, ' .
  32. 'a.catid, a.created, a.created_by, a.created_by_alias, ' .
  33. // use created if modified is 0
  34. 'CASE WHEN a.modified = ' . $db->q($db->getNullDate()) . ' THEN a.created ELSE a.modified END as modified, ' .
  35. 'a.modified_by, uam.name as modified_by_name,' .
  36. // use created if publish_up is 0
  37. 'CASE WHEN a.publish_up = ' . $db->q($db->getNullDate()) . ' THEN a.created ELSE a.publish_up END as publish_up,' .
  38. 'a.publish_down, a.images, a.urls, a.attribs, a.metadata, a.metakey, a.metadesc, a.access, ' .
  39. 'a.hits, a.xreference, a.featured'
  40. );
  41.  
  42. $app = JFactory::getApplication();
  43. $appParams = $app->getParams();
  44.  
  45. $articles->setState('params', $appParams);
  46. // Set the filters based on the module params
  47. $articles->setState('list.start', 0);
  48. $articles->setState('list.limit', (int) $_params->get('count', 0)+1);
  49. $articles->setState('filter.published', 1);
  50.  
  51. // Access filter
  52. $access = !JComponentHelper::getParams('com_content')->get('show_noauth');
  53. $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
  54. $articles->setState('filter.access', $access);
  55.  
  56. // Category filter
  57. $catids = $_params->get('depends');
  58. if ($catids != null) {
  59. if ($_params->get('show_child_category_articles', 0) && (int) $_params->get('levels', 0) > 0) {
  60. // Get an instance of the generic categories model
  61. $categories = JModelLegacy::getInstance('Categories', 'ContentModel', array('ignore_request' => true));
  62. $categories->setState('params', $appParams);
  63. $levels = $_params->get('levels', 1) ? $_params->get('levels', 1) : 9999;
  64. $categories->setState('filter.get_children', $levels);
  65. $categories->setState('filter.published', 1);
  66. $categories->setState('filter.access', $access);
  67. $additional_catids = array();
  68.  
  69. foreach($catids as $catid)
  70. {
  71. $categories->setState('filter.parentId', $catid);
  72. $recursive = true;
  73. $items = $categories->getItems($recursive);
  74.  
  75. if ($items)
  76. {
  77. foreach($items as $category)
  78. {
  79. $condition = (($category->level - $categories->getParent()->level) <= $levels);
  80. if ($condition) {
  81. $additional_catids[] = $category->id;
  82. }
  83.  
  84. }
  85. }
  86. }
  87.  
  88. $catids = array_unique(array_merge($catids, $additional_catids));
  89. }
  90. $articles->setState('filter.category_id', $catids);
  91.  
  92. // Ordering
  93. $articles->setState('list.ordering', $_params->get('article_ordering', 'a.ordering'));
  94. $articles->setState('list.direction', $_params->get('article_ordering_direction', 'ASC'));
  95.  
  96. // // New Parameters
  97. $articles->setState('filter.featured', $_params->get('show_front', 'show'));
  98.  
  99. // Filter by language
  100. $articles->setState('filter.language', $app->getLanguageFilter());
  101.  
  102. $items = $articles->getItems();
  103. //var_dump($items); die("ancnc");
  104. //$show_introtext = $_params->get('show_introtext', 0);
  105. //$introtext_limit = $_params->get('introtext_limit', 100);
  106. $title_limit = $_params->get('item_title_max_characs', 20);
  107.  
  108. // Find current Article ID if on an article page
  109. $option = $app->input->get('option');
  110. $view = $app->input->get('view');
  111.  
  112. if ($option === 'com_content' && $view === 'article') {
  113. $active_article_id = $app->input->getInt('id');
  114. }
  115. else {
  116. $active_article_id = 0;
  117. }
  118.  
  119. // Prepare data for display using display options
  120. foreach ($items as &$item)
  121. {
  122. $item->slug = $item->id.':'.$item->alias;
  123. $item->catslug = $item->catid ? $item->catid .':'.$item->category_alias : $item->catid;
  124.  
  125. if ($access || in_array($item->access, $authorised))
  126. {
  127. // We know that user has the privilege to view the article
  128. $item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catslug));
  129. }
  130. else
  131. {
  132. $app = JFactory::getApplication();
  133. $menu = $app->getMenu();
  134. $menuitems = $menu->getItems('link', 'index.php?option=com_users&view=login');
  135. if (isset($menuitems[0]))
  136. {
  137. $Itemid = $menuitems[0]->id;
  138. }
  139. elseif ($app->input->getInt('Itemid') > 0)
  140. {
  141. // Use Itemid from requesting page only if there is no existing menu
  142. $Itemid = $app->input->getInt('Itemid');
  143. }
  144. $item->link = JRoute::_('index.php?option=com_users&view=login&Itemid='.$Itemid);
  145. }
  146.  
  147. // Used for styling the active article
  148. $item->active = $item->id == $active_article_id ? 'active' : '';
  149. $item->title = BaseHelper::truncate($item->title, $title_limit);
  150. //if ($show_introtext) {
  151. // $item->introtext = JHtml::_('content.prepare', $item->introtext, '', 'plg_content_relatednews.content');
  152. // self::getImages($item, $_params);
  153. // $item->introtext = self::_cleanIntrotext($item->introtext);
  154. //} else {
  155. $item->introtext = JHtml::_('content.prepare', $item->introtext, '', 'plg_content_relatednews.content');
  156. BaseHelper::getArticleImages($item, $_params);
  157. //}
  158. //$item->displayIntrotext = $show_introtext ? self::truncate($item->introtext, $introtext_limit) : '';
  159. //$item->displayReadmore = $item->alternative_readmore;
  160. }
  161. return $items;
  162. }
  163. }
  164.  
  165. public static function groupBy($list, $fieldName, $article_grouping_direction, $fieldNameToKeep = null)
  166. {
  167. $grouped = array();
  168.  
  169. if (!is_array($list)) {
  170. if ($list == '') {
  171. return $grouped;
  172. }
  173.  
  174. $list = array($list);
  175. }
  176.  
  177. foreach($list as $key => $item)
  178. {
  179. if (!isset($grouped[$item->$fieldName])) {
  180. $grouped[$item->$fieldName] = array();
  181. }
  182.  
  183. if (is_null($fieldNameToKeep)) {
  184. $grouped[$item->$fieldName][$key] = $item;
  185. }
  186. else {
  187. $grouped[$item->$fieldName][$key] = $item->$fieldNameToKeep;
  188. }
  189.  
  190. unset($list[$key]);
  191. }
  192.  
  193. $article_grouping_direction($grouped);
  194.  
  195. return $grouped;
  196. }
  197.  
  198. public static function groupByDate($list, $type = 'year', $article_grouping_direction, $month_year_format = 'F Y')
  199. {
  200. $grouped = array();
  201.  
  202. if (!is_array($list)) {
  203. if ($list == '') {
  204. return $grouped;
  205. }
  206.  
  207. $list = array($list);
  208. }
  209.  
  210. foreach($list as $key => $item)
  211. {
  212. switch($type)
  213. {
  214. case 'month_year':
  215. $month_year = JString::substr($item->created, 0, 7);
  216.  
  217. if (!isset($grouped[$month_year])) {
  218. $grouped[$month_year] = array();
  219. }
  220.  
  221. $grouped[$month_year][$key] = $item;
  222. break;
  223.  
  224. case 'year':
  225. default:
  226. $year = JString::substr($item->created, 0, 4);
  227.  
  228. if (!isset($grouped[$year])) {
  229. $grouped[$year] = array();
  230. }
  231.  
  232. $grouped[$year][$key] = $item;
  233. break;
  234. }
  235.  
  236. unset($list[$key]);
  237. }
  238.  
  239. $article_grouping_direction($grouped);
  240.  
  241. if ($type === 'month_year') {
  242. foreach($grouped as $group => $items)
  243. {
  244. $date = new JDate($group);
  245. $formatted_group = $date->format($month_year_format);
  246. $grouped[$formatted_group] = $items;
  247. unset($grouped[$group]);
  248. }
  249. }
  250.  
  251. return $grouped;
  252. }
  253.  
  254.  
  255. }
  256.  
  257. <field name="article_ordering" type="list" default="a.title"
  258. label="Article Field to Order By"
  259. description="Select which field you would like Articles to be ordered by. Featured Ordering should only be used when Filtering Option for Featured Articles is set to 'Only'.">
  260.  
  261. <option value="a.metakey">Article Kewords Order</option>
  262. <option value="a.ordering">Article Manager Order</option>
  263. <option value="fp.ordering">Featured Articles Order</option>
  264. <option value="a.hits">Hits</option>
  265. <option value="a.title">Title</option>
  266. <option value="a.id">ID</option>
  267. <option value="a.alias">Alias</option>
  268. <option value="a.created">Created Date</option>
  269. <option value="modified">Modified Date</option>
  270. <option value="publish_up">Start Publishing Date</option>
  271. <option value="a.publish_down">Finish Publishing Date</option>
  272. </field>
  273.  
  274. <?php
  275. /**
  276. * @package Related News
  277. * @version 2.5
  278. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
  279. * @copyright (c) 2012 YouTech Company. All Rights Reserved.
  280. * @author YouTech Company http://www.smartaddons.com
  281. *
  282. */
  283. defined('_JEXEC') or die;
  284. require_once JPATH_SITE.'/libraries/joomla/filesystem/folder.php';
  285. JLoader::register('ImageHelper', dirname(__FILE__).'/helper_image.php');
  286.  
  287. if (!class_exists('BaseHelper')){
  288. abstract class BaseHelper{
  289.  
  290. /**
  291. *
  292. * @param string $introtext
  293. * @return string
  294. */
  295. public function _cleanText($text){
  296. $text = str_replace('<p>', ' ', $text);
  297. $text = str_replace('</p>', ' ', $text);
  298. $text = strip_tags($text, '<a><em><strong>');
  299. $text = trim($text);
  300. return $text;
  301. }
  302.  
  303. /**
  304. * Parse and build target attribute for links.
  305. * @param string $value (_self, _blank, _windowopen, _modal)
  306. */
  307. public static function parseTarget($value='_self'){
  308. $target = '';
  309. switch($value){
  310. default:
  311. case '0':
  312. case '_self':
  313. break;
  314. case '1':
  315. case '_blank':
  316. $target = "target="_blank"";
  317. break;
  318. case '2':
  319. case '_windowopen':
  320. $target = "onclick="window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,false');return false;"";
  321. break;
  322. case '3':
  323. case '_modal':
  324. $target = "";
  325. break;
  326. }
  327. return $target;
  328. }
  329.  
  330. /**
  331. * Truncate string by $length
  332. * @param string $string
  333. * @param int $length
  334. * @param string $etc
  335. * @return string
  336. */
  337. public static function truncate($string, $length, $etc='...'){
  338. return defined('MB_OVERLOAD_STRING')
  339. ? self::_mb_truncate($string, $length, $etc)
  340. : self::_truncate($string, $length, $etc);
  341. }
  342.  
  343. /**
  344. * Truncate string if it's size over $length
  345. * @param string $string
  346. * @param int $length
  347. * @param string $etc
  348. * @return string
  349. */
  350. private static function _truncate($string, $length, $etc='...'){
  351. if ($length>0 && $length<strlen($string)){
  352. $buffer = '';
  353. $buffer_length = 0;
  354. $parts = preg_split('/(<[^>]*>)/', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
  355. $self_closing_tag = split(',', 'area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed');
  356. $open = array();
  357.  
  358. foreach($parts as $i => $s){
  359. if( false===strpos($s, '<') ){
  360. $s_length = strlen($s);
  361. if ($buffer_length + $s_length < $length){
  362. $buffer .= $s;
  363. $buffer_length += $s_length;
  364. } else if ($buffer_length + $s_length == $length) {
  365. if ( !empty($etc) ){
  366. $buffer .= ($s[$s_length - 1]==' ') ? $etc : " $etc";
  367. }
  368. break;
  369. } else {
  370. $words = preg_split('/([^s]*)/', $s, - 1, PREG_SPLIT_DELIM_CAPTURE);
  371. $space_end = false;
  372. foreach ($words as $w){
  373. if ($w_length = strlen($w)){
  374. if ($buffer_length + $w_length < $length){
  375. $buffer .= $w;
  376. $buffer_length += $w_length;
  377. $space_end = (trim($w) == '');
  378. } else {
  379. if ( !empty($etc) ){
  380. $more = $space_end ? $etc : " $etc";
  381. $buffer .= $more;
  382. $buffer_length += strlen($more);
  383. }
  384. break;
  385. }
  386. }
  387. }
  388. break;
  389. }
  390. } else {
  391. preg_match('/^<([/]?s?)([a-zA-Z0-9]+)s?[^>]*>$/', $s, $m);
  392. //$tagclose = isset($m[1]) && trim($m[1])=='/';
  393. if (empty($m[1]) && isset($m[2]) && !in_array($m[2], $self_closing_tag)){
  394. array_push($open, $m[2]);
  395. } else if (trim($m[1])=='/') {
  396. $tag = array_pop($open);
  397. if ($tag != $m[2]){
  398. // uncomment to to check invalid html string.
  399. // die('invalid close tag: '. $s);
  400. }
  401. }
  402. $buffer .= $s;
  403. }
  404. }
  405. // close tag openned.
  406. while(count($open)>0){
  407. $tag = array_pop($open);
  408. $buffer .= "</$tag>";
  409. }
  410. return $buffer;
  411. }
  412. return $string;
  413. }
  414.  
  415. /**
  416. * Truncate mutibyte string if it's size over $length
  417. * @param string $string
  418. * @param int $length
  419. * @param string $etc
  420. * @return string
  421. */
  422. private static function _mb_truncate($string, $length, $etc='...'){
  423. $encoding = mb_detect_encoding($string);
  424. if ($length>0 && $length<mb_strlen($string, $encoding)){
  425. $buffer = '';
  426. $buffer_length = 0;
  427. $parts = preg_split('/(<[^>]*>)/', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
  428. $self_closing_tag = explode(',', 'area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed');
  429. $open = array();
  430.  
  431. foreach($parts as $i => $s){
  432. if (false === mb_strpos($s, '<')){
  433. $s_length = mb_strlen($s, $encoding);
  434. if ($buffer_length + $s_length < $length){
  435. $buffer .= $s;
  436. $buffer_length += $s_length;
  437. } else if ($buffer_length + $s_length == $length) {
  438. if ( !empty($etc) ){
  439. $buffer .= ($s[$s_length - 1]==' ') ? $etc : " $etc";
  440. }
  441. break;
  442. } else {
  443. $words = preg_split('/([^s]*)/', $s, -1, PREG_SPLIT_DELIM_CAPTURE);
  444. $space_end = false;
  445. foreach ($words as $w){
  446. if ($w_length = mb_strlen($w, $encoding)){
  447. if ($buffer_length + $w_length < $length){
  448. $buffer .= $w;
  449. $buffer_length += $w_length;
  450. $space_end = (trim($w) == '');
  451. } else {
  452. if ( !empty($etc) ){
  453. $more = $space_end ? $etc : " $etc";
  454. $buffer .= $more;
  455. $buffer_length += mb_strlen($more);
  456. }
  457. break;
  458. }
  459. }
  460. }
  461. break;
  462. }
  463. } else {
  464. preg_match('/^<([/]?s?)([a-zA-Z0-9]+)s?[^>]*>$/', $s, $m);
  465. //$tagclose = isset($m[1]) && trim($m[1])=='/';
  466. if (empty($m[1]) && isset($m[2]) && !in_array($m[2], $self_closing_tag)){
  467. array_push($open, $m[2]);
  468. } else if (trim($m[1])=='/') {
  469. $tag = array_pop($open);
  470. if ($tag != $m[2]){
  471. // uncomment to to check invalid html string.
  472. // die('invalid close tag: '. $s);
  473. }
  474. }
  475. $buffer .= $s;
  476. }
  477. }
  478. // close tag openned.
  479. while(count($open)>0){
  480. $tag = array_pop($open);
  481. $buffer .= "</$tag>";
  482. }
  483. return $buffer;
  484. }
  485. return $string;
  486. }
  487.  
  488.  
  489. public static $image_article_cache = array();
  490. public static function getArticleImage($item, $_params, $ctype='article'){
  491. $images = &self::getArticleImages($item, $_params, $ctype);
  492. return is_array($images) && count($images) ? $images[0] : null;
  493. }
  494.  
  495. public static function getArticleImages($item, $_params, $ctype='article'){
  496. $hash = md5( serialize(array($_params, $ctype)) );
  497. if ( !isset(self::$image_article_cache[$hash][$item->id]) ){
  498. $defaults = array(
  499. 'external' => 1,
  500. 'image_intro' => 1,
  501. 'inline_introtext' => 1,
  502. 'image_fulltext' => 1,
  503. 'inline_fulltext' => 1
  504. );
  505. $images_path = array();
  506. $priority = preg_split('/[s|,|;]/', $_params->get('imgcfg_order', 'external, imagE_intro,inline_introtext,image_fulltext,inline_fulltext'), -1, PREG_SPLIT_NO_EMPTY);
  507. if ( count($priority) > 0 ){
  508. $priority = array_map('strtolower', $priority);
  509. $mark = array();
  510.  
  511. for($i=0; $i<count($priority); $i++){
  512. $type = $priority[$i];
  513. if ( array_key_exists($type, $defaults) )
  514. unset($defaults[ $type ]);
  515. if ( $_params->get('imgcfg_from_'.$type, 1) )
  516. $mark[ $type ] = 1;
  517. }
  518. }
  519. foreach($defaults as $type => $val){
  520. if ( $_params->get('imgcfg_from_'.$type, 1) )
  521. $mark[ $type ] = 1;
  522. }
  523. if ( count($mark) > 0 ){
  524. // prepare data.
  525. $images_data = null;
  526. if (array_key_exists('image_intro', $mark) || array_key_exists('image_fulltext', $mark)){
  527. $images_data = json_decode($item->images, true);
  528. }
  529.  
  530. foreach($mark as $type => $true){
  531. switch ($type){
  532. case 'image_intro':
  533. case 'image_fulltext':
  534. if ( isset($images_data) && isset($images_data[$type]) && !empty($images_data[$type])){
  535. $image = array(
  536. 'src' => $images_data[$type]
  537. );
  538. if (array_key_exists($type.'_alt', $images_data)){
  539. $image['alt'] = $images_data[$type.'_alt'];
  540. }
  541. if (array_key_exists($type.'_caption', $images_data)){
  542. /* $image['class'] = 'caption'; */
  543. $image['title'] = $images_data[$type.'_caption'];
  544. }
  545. array_push($images_path, $image);
  546. }
  547. break;
  548. case 'inline_introtext':
  549. $text = $item->introtext;
  550. case 'inline_fulltext':
  551. if ($type == 'inline_fulltext'){
  552. $text = $item->fulltext;
  553. }
  554. $inline_images = self::getInlineImages($text);
  555. for ($i=0; $i<count($inline_images); $i++){
  556. array_push($images_path, $inline_images[$i]);
  557. }
  558. break;
  559.  
  560. case 'external':
  561. $exf = $_params->get('imgcfg_external_url', '/images');
  562. preg_match_all('/{([a-zA-Z0-9_]+)}/', $exf, $m);
  563. if ( count($m)==2 && count($m[0])>0 ){
  564. $compat = 1;
  565. foreach ($m[1] as $property){
  566. !property_exists($item, $property) && ($compat=0);
  567. }
  568. if ($compat){
  569. $replace = array();
  570. foreach ($m[1] as $property){
  571. $replace[] = is_null($item->$property) ? '' : $item->$property;
  572. }
  573. $exf = str_replace($m[0], $replace, $exf);
  574. }
  575. }
  576. $files = self::getExternalImages($exf);
  577. for ($i=0; $i<count($files); $i++){
  578. array_push($images_path, array('src'=>$files[$i]));
  579. }
  580. break;
  581. default:
  582. break;
  583. }
  584. }
  585. }
  586.  
  587. if ( count($images_path) == 0 && $_params->get('imgcfg_placeholder', 1)==1){
  588. $images_path[] = array('src'=> $_params->get('imgcfg_placeholder_path', null), 'class'=>'placeholder');
  589. }
  590.  
  591. self::$image_article_cache[$hash][$item->id] = $images_path;
  592. }
  593. return self::$image_article_cache[$hash][$item->id];
  594. }
  595.  
  596. public static $image_category_cache = array();
  597. public static function getCategoryImage($item, $_params, $ctype='category'){
  598. $images = &self::getCategoryImages($item, $_params, $ctype);
  599. return is_array($images) && count($images) ? $images[0] : null;
  600. }
  601.  
  602. public static function getCategoryImages($item, $_params, $ctype='category'){
  603. $hash = md5( serialize(array($_params, $ctype)) );
  604. if ( !isset(self::$image_category_cache[$hash][$item->id]) ){
  605. $defaults = array(
  606. 'external' => 1,
  607. 'params' => 1,
  608. 'description' => 1
  609. );
  610. $images_path = array();
  611. $priority = preg_split('/[s|,|;]/', $_params->get('imgcfg_order', 'external, params, description'), -1, PREG_SPLIT_NO_EMPTY);
  612. if ( count($priority) > 0 ){
  613. $priority = array_map('strtolower', $priority);
  614. $mark = array();
  615.  
  616. for($i=0; $i<count($priority); $i++){
  617. $type = $priority[$i];
  618. if ( array_key_exists($type, $defaults) )
  619. unset($defaults[ $type ]);
  620. if ( $_params->get('imgcfg_from_'.$type, 1) )
  621. $mark[ $type ] = 1;
  622. }
  623. }
  624. foreach($defaults as $type => $val){
  625. if ( $_params->get('imgcfg_from_'.$type, 1) )
  626. $mark[ $type ] = 1;
  627. }
  628. if ( count($mark) > 0 ){
  629. $cparams = null;
  630. if (array_key_exists('params', $mark)){
  631. $cparams = new JRegistry;
  632. $cparams->loadString($item->params);
  633. }
  634.  
  635. foreach($mark as $type => $true){
  636. switch ($type){
  637. case 'params':
  638. if ( $cparams instanceof JRegistry && $cparams->get('image') ){
  639. $image = array(
  640. 'src' => $cparams->get('image')
  641. );
  642. array_push($images_path, $image);
  643. }
  644. break;
  645. case 'description':
  646. $inline_images = self::getInlineImages($item->description);
  647. for ($i=0; $i<count($inline_images); $i++){
  648. array_push($images_path, $inline_images[$i]);
  649. }
  650. break;
  651.  
  652. case 'external':
  653. $exf = $_params->get('imgcfg_external_url', '/images');
  654. preg_match_all('/{([a-zA-Z0-9_]+)}/', $exf, $m);
  655. if ( count($m)==2 && count($m[0])>0 ){
  656. $compat = 1;
  657. foreach ($m[1] as $property){
  658. !property_exists($item, $property) && ($compat=0);
  659. }
  660. if ($compat){
  661. $replace = array();
  662. foreach ($m[1] as $property){
  663. $replace[] = is_null($item->$property) ? '' : $item->$property;
  664. }
  665. $exf = str_replace($m[0], $replace, $exf);
  666. }
  667. }
  668. $files = self::getExternalImages($exf);
  669. for ($i=0; $i<count($files); $i++){
  670. array_push($images_path, array('src'=>$files[$i]));
  671. }
  672. break;
  673. default:
  674. break;
  675. }
  676. }
  677. }
  678.  
  679. if ( count($images_path) == 0 && $_params->get('imgcfg_placeholder', 1)==1){
  680. $images_path[] = array('src'=> $_params->get('imgcfg_placeholder_path', null), 'class'=>'placeholder');
  681. }
  682.  
  683. self::$image_category_cache[$hash][$item->id] = $images_path;
  684. }
  685. return self::$image_category_cache[$hash][$item->id];
  686. }
  687.  
  688. /**
  689. *
  690. * @param string $text
  691. * @return string:
  692. */
  693. public static function getInlineImages($text){
  694. $images = array();
  695. $searchTags = array(
  696. 'img' => '/<img[^>]+>/i',
  697. 'input' => '/<input[^>]+types?=s?"image"[^>]+>/i'
  698. );
  699. foreach ($searchTags as $tag => $regex){
  700. preg_match_all($regex, $text, $m);
  701. if ( is_array($m) && isset($m[0]) && count($m[0])){
  702. foreach ($m[0] as $htmltag){
  703. $tmp = JUtility::parseAttributes($htmltag);
  704. if ( isset($tmp['src']) ){
  705. if ($tag == 'input'){
  706. array_push( $images, array('src' => $tmp['src']) );
  707. } else {
  708. array_push( $images, $tmp );
  709. }
  710. }
  711. }
  712. }
  713. }
  714. return $images;
  715. }
  716.  
  717. /**
  718. *
  719. * @param string $path
  720. * @return multitype:multitype:unknown |Ambigous <multitype:, boolean, multitype:unknown multitype:unknown >
  721. */
  722. public static function getExternalImages($path){
  723. $files = array();
  724. $ps = JString::parse_url($path);
  725. if ( array_key_exists('path', $ps) && !empty($ps['path']) ){
  726. $isHttp = isset($ps['scheme']) && in_array($ps['scheme'], array('http', 'https'));
  727. if (!$isHttp || JURI::isInternal($path)){
  728. // image on server
  729. $path = $ps['path'];
  730. } else {
  731. $files[] = array( 'src' => $path );
  732. return $files;
  733. }
  734. }
  735.  
  736. if (is_file($path)){
  737. $files[] = $path;
  738. } else if (is_dir($path)){
  739. $files = JFolder::files($path, '.jpg|.png|.gif', false, true);
  740. } else {
  741. $ext = substr($path, -4);
  742. $search = substr($path, 0, -4);
  743. $lext = strtolower($ext);
  744. if ( is_dir($search) && in_array($lext, array('.jpg', '.png', '.gif')) ){
  745. $files = JFolder::files($search, $ext, false, true);
  746. }
  747. }
  748. return $files;
  749. }
  750.  
  751. public static function imageTag($image, $options=array()){
  752. return ImageHelper::init($image, $options)->tag();
  753. }
  754.  
  755. public static function getImageHelper($image, $options=array()){
  756. return ImageHelper::init($image, $options);
  757. }
  758.  
  759. }
  760. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement