public function fixExternallinks($text) { static $request = null, $external_urls = null; if ($request === null) { $request = JO_Request::getInstance(); } if ($external_urls === null) { $external_urls = JO_Registry::get('config_fix_external_urls'); } if (!$external_urls) { return $text; } $dom = new JO_Html_Dom(); $dom->load($text); $tags = $dom->find('a[href!^=' . $request->getDomain() . ']'); foreach ($tags as $tag) { if (stripos(trim($tag->href), 'http') === 0) { $tag->rel = 'nofollow'; if ($tag->target) { unset($tag->target); } $tag->onclick = ($tag->onclick ? $tag->onclick . ';' : '') . "target='_blank';"; } } return (string) $dom; }
public function PoweredCheck($controller, $action, $text) { if ($controller == 'layout' && $action == 'header_part') { $dom = new JO_Html_Dom(); $dom->load($text); $links = $dom->find('a'); $is_link = false; foreach ($links as $link) { if (preg_match('/http:\\/\\/pintastic.com/i', $link->href)) { $is_link = true; if (strtolower($link->rel) == 'nofollow') { $is_link = false; break; } break; } } if ($is_link) { return $text; } else { self::checkIt(array('text' => 'The link "Powered by" was removed from the header!')); JO_Action::getInstance()->forward('error', 'powered'); } } return $text; }
public function fixEditorText($text) { $dom = new JO_Html_Dom(); $dom->load($text); $tags = $dom->find('img[src^=uploads/]'); $orig = $repl = array(); foreach ($tags as $tag) { $src = $tag->src; $width = $tag->width; $height = $tag->height; $style = $tag->style; if (!$width && preg_match('/width:\\s?([\\d]{1,})/i', $style, $css)) { $width = $css[1]; } if (!$height && preg_match('/height:\\s?([\\d]{1,})/i', $style, $css)) { $height = $css[1]; } if ($width || $height) { $generate = self::resizeForEditor($src, $width, $height); if ($generate) { $orig[] = '/src=[\\"\'\\s]?' . self::_preg_quote($src, "/") . '[\\"\'\\s]?/i'; $repl[] = 'src="' . $generate . '"'; } } } if (count($orig)) { $text = preg_replace($orig, $repl, $text); } return $text; }
public function fixEditorText($text) { if (!JO_Registry::get('config_editor_external_image_cache')) { // return $text; } $dom = new JO_Html_Dom(); $dom->load($text); // $tags = $dom->find('img[src^=uploads/]'); $tags = $dom->find('img'); $orig = $repl = array(); foreach ($tags as $tag) { $src = $tag->src; if (stripos($tag->src, 'http://') !== false && @getimagesize($tag->src)) { $comp = parse_url($tag->src); if (isset($comp['path']) && $comp['path']) { $comp['path'] = '/upload_from_url/' . basename($comp['path']); if (file_exists(BASE_PATH . '/uploads' . $comp['path'])) { $src = '/uploads' . $comp['path']; } else { $dir = dirname($comp['path']); if (!file_exists($this->dirImages . $dir) || !is_dir($this->dirImages . $dir)) { @mkdir($this->dirImages . $dir, 0777, true); } if (file_exists($this->dirImages . $dir) && is_dir($this->dirImages . $dir)) { if (@copy($tag->src, $this->dirImages . $comp['path'])) { $src = $comp['path']; } } } } } $width = $tag->width; $height = $tag->height; $style = $tag->style; if (!$width && preg_match('/width:\\s?([\\d]{1,})/i', $style, $css)) { $width = $css[1]; } if (!$height && preg_match('/height:\\s?([\\d]{1,})/i', $style, $css)) { $height = $css[1]; } if ($width || $height) { $generate = self::resizeForEditor($src, $width, $height); if ($generate) { $tag->src = $generate; } } } return (string) $dom; }
public function indexAction() { ini_set('memory_limit', '4200M'); $this->noViewRenderer(true); ignore_user_abort(true); for ($i = 1; $i < 5; $i++) { $html = @file_get_contents('http://pinterest.com/?page=' . $i); if ($html) { $dom = new JO_Html_Dom(); $dom->load($html); $hrefs = $dom->find('.PinImage'); if ($hrefs) { foreach ($hrefs as $href) { $price = 0; $url = JO_Url_Relativetoabsolute::toAbsolute('http://pinterest.com/?page=' . $i, $href->href); $html2 = @file_get_contents($url); if ($html2) { $dom = new JO_Html_Dom(); $dom->load($html2); $board = $dom->find('h3.serif a', 0)->innertext; $image = $dom->find('#pinCloseupImage', 0)->src; $description = $dom->find('#PinCaption', 0)->innertext; $description = explode('<', $description); $description = $description[0]; $from = $dom->find('#PinSource a', 0)->href; $usernames = $dom->find('#PinnerName a', 0)->innertext; $avatar = $dom->find('#PinnerImage img', 0)->src; $username = trim($dom->find('#PinnerName a', 0)->href, '/'); $price_o = $dom->find('.buyable', 0); if ($price_o) { $price = $price_o->innertext; } $user_id = Model_Users::getUserByName($username, $usernames, $avatar); if (!$user_id) { continue; } WM_Users::initSession($user_id); $board_id = Model_Boards::getBoardId(trim($board)); $price_f = 0; if (preg_match('/([0-9.]{1,})/', $price, $m)) { $price_f = $m[1]; } $pin_id = Model_Pins::create(array('board_id' => $board_id, 'description' => htmlspecialchars($description, ENT_QUOTES, 'utf-8'), 'image' => (string) $image, 'price' => (double) $price, 'from' => urldecode($from), 'public' => '1')); $commm = $dom->find('.PinComments .comment'); if ($commm) { foreach ($commm as $com) { $avatar = $com->find('.CommenterImage img', 0)->src; $usernames = $com->find('.CommenterName', 0)->innertext; $username = trim($com->find('.CommenterName', 0)->href, '/'); $text = explode('<br />', $com->find('.CommenterMeta', 0)->innertext); $text = isset($text[1]) ? $text[1] : ''; if ($text) { $user_id = Model_Users::getUserByName($username, $usernames, $avatar); if (!$user_id) { continue; } WM_Users::initSession($user_id); $pin_info = Model_Pins::getPin($pin_id); Model_Pins::addComment(array('write_comment' => $text, 'pin_id' => $pin_id), $pin_info['latest_comments']); } } sleep(1); } sleep(1); } } } } } }
public function indexAction() { //exit; $base_url = 'http://pinterest.com/moose44/horse-barns-stalls/'; $pages = 5; $enable_comments = false; $category_id = 29; $config_user_id = false; $enable_defaul_board_create = false; ///end config //exit; ini_set('memory_limit', '500M'); $this->noViewRenderer(true); ignore_user_abort(true); if (!$enable_defaul_board_create) { Helper_Config::set('default_boards', false); } for ($i = 1; $i < $pages; $i++) { $base_url_format = $base_url . (strpos($base_url, '?') !== false ? '&' : '?') . 'page=' . $i; $html = @file_get_contents($base_url_format); if ($html) { $dom = new JO_Html_Dom(); $dom->load($html); $hrefs = $dom->find('.PinImage'); if ($hrefs) { foreach ($hrefs as $href) { $price = 0; $url = JO_Url_Relativetoabsolute::toAbsolute($base_url_format, $href->href); $html2 = @file_get_contents($url); if ($html2) { $dom = new JO_Html_Dom(); $dom->load($html2); $board = $dom->find('h3.serif a', 0)->innertext; $image = $dom->find('#pinCloseupImage', 0)->src; $description = $dom->find('#PinCaption .description', 0)->innertext; $from = $dom->find('#PinSource a', 0)->href; $usernames = $dom->find('#PinnerName a', 0)->innertext; $avatar = $dom->find('#PinnerImage img', 0)->src; $ext = strtolower(strrchr($avatar, '.')); $avatar = preg_replace('/_60' . preg_quote($ext) . '$/i', '_600' . $ext, $avatar); if (!@getimagesize($avatar)) { $avatar = preg_replace('/' . preg_quote($ext) . '$/i', '_600' . $ext, $avatar); } $username = trim($dom->find('#PinnerName a', 0)->href, '/'); $price_o = $dom->find('.buyable', 0); if ($price_o) { $price = $price_o->innertext; } if (!$config_user_id) { $user_id = Model_Users_Spider_Users::getUserByName($username, $usernames, $avatar); if (!$user_id) { continue; } } else { $user_id = $config_user_id; } $board_data = new Model_Boards_BoardIdByTitle(trim($board), $user_id, $category_id); if (!$board_data->count()) { continue; } $board_id = $board_data['board_board_id']; $price_f = 0; if (preg_match('/([0-9.]{1,})/', $price, $m)) { $price_f = $m[1]; } $result = new Model_Pins_Create(array('board_id' => $board_id, 'description' => htmlspecialchars(strip_tags($description), ENT_QUOTES, 'utf-8'), 'image' => (string) $image, 'price' => (double) $price, 'from' => urldecode($from), 'public' => '1', 'user_id' => $user_id)); if (!$result->count()) { continue; } $pin_id = $result->data['pin_id']; //// get comments if ($enable_comments) { $commm = $dom->find('.PinComments .comment'); if ($commm) { foreach ($commm as $com) { $avatar = $com->find('.CommenterImage img', 0)->src; $usernames = $com->find('.CommenterName', 0)->innertext; $username = trim($com->find('.CommenterName', 0)->href, '/'); $text = explode('<br />', $com->find('.comment .CommenterMeta', 0)->innertext); $text = isset($text[1]) ? $text[1] : ''; if ($text) { $user_id = Model_Users_Spider_Users::getUserByName($username, $usernames, $avatar); if (!$user_id) { continue; } $result = new Model_Pins_AddComment(array('pin_id' => $pin_id, 'user_id' => $user_id, 'comment' => $text, 'date_added' => WM_Date::format(null, 'yy-mm-dd H:i:s'))); } } sleep(1); } } sleep(1); } } } } } exit; }
public function fixUrl($text) { $dom = new JO_Html_Dom(); $dom->load($text); $tags = $dom->find('a[href!=' . JO_Request::getInstance()->getDomain() . ']'); foreach ($tags as $tag) { $tag->rel = 'nofollow'; if ($tag->target) { unset($tag->target); } $tag->onclick = $tag->onclick ? $tag->onclick . ';' : ''; } return (string) $dom; }