Example #1
0
 /**
  *  sets the token in memcache for this uploader
  */
 public function setMemToken()
 {
     $vars = get_object_vars($this);
     $this->_token = md5(serialize($vars));
     $mem_key = 'vf_gallery:' . $this->_token;
     mem($mem_key, $vars);
 }
 private function fast_master_find_db($read_db)
 {
     $repmgr_cluster_name =& $GLOBALS['repmgr_cluster_name'];
     if ($mem = mem($mem_key = "repmgr:{$repmgr_cluster_name} master")) {
         return $GLOBALS['dbw_host'] = $mem;
     }
     if (!$read_db) {
         $read_db = $GLOBALS['db_host'];
         #not by reference because we may meed to reassign
     }
     if ($read_db == 'localhost') {
         $read_db = trim(rtrim(`hostname`));
     }
     $repmgr_cluster_name =& $GLOBALS['repmgr_cluster_name'];
     $db =& $GLOBALS['db'];
     if ($rs = $db->Execute("select id, conninfo from repmgr_{$repmgr_cluster_name}.repl_nodes")) {
         $nodes = array();
         $read_id = NULL;
         while (!$rs->EOF) {
             $nodes[($fields =& $rs->fields) ? $id =& $fields['id'] : NULL] = $conninfo =& $fields['conninfo'];
             #we only want to call fields once, for speed
             if (!$read_id && strpos($conninfo, $read_db) !== false) {
                 $read_id = $id;
             }
             $rs->MoveNext();
         }
         if ($rs = $db->Execute("select distinct primary_node from repmgr_{$repmgr_cluster_name}.repl_monitor where standby_node = {$read_id}")) {
             $write_conninfo = $nodes[$rs->Fields('primary_node')];
             return mem($mem_key, $GLOBALS['dbw_host'] = substr($write_conninfo, ($offset = strpos($write_conninfo, 'host=')) + 5, strpos($write_conninfo, ' ', $offset) - $offset - 5));
         }
     }
     $GLOBALS['dbw_host'] = NULL;
 }
function collection($model, $clause, $duration = null)
{
    $key = "aql:get:{$model}:" . substr(md5(serialize($clause)), 0, 250);
    $collection = mem($key);
    if (!$collection) {
        $aql = aql::get_aql($model);
        // make minimal sql
        $aql_array = aql2array($aql);
        foreach ($aql_array as $i => $block) {
            unset($aql_array[$i]['objects']);
            unset($aql_array[$i]['fields']);
            unset($aql_array[$i]['subqueries']);
        }
        $sql_array = aql::make_sql_array($aql_array, aql::check_clause_array($aql_array, $clause));
        $minimal_sql = $sql_array['sql'];
        $r = sql($minimal_sql);
        $collection = array();
        while (!$r->EOF) {
            $collection[] = $r->Fields(0);
            $r->MoveNext();
        }
        #print_a($collection);
        mem($key, $collection, $duration);
    }
    if (is_array($collection)) {
        //print_a($collection);
        foreach ($collection as $id) {
            $obj = Model::get($model, $id);
            $ret[] = $obj->dataToArray();
        }
        return $ret;
    } else {
        return false;
    }
}
Example #4
0
if (!$cache_refresh) {
    \elapsed("Footer : Getting the markets from cache");
    $markets = mem($cache_name);
}
if (!$markets) {
    $markets = [];
    $marketIds = \Crave\Model\market::getSlugsFeed(['ct_promoter_website_id' => $website->ct_promoter_website_id, 'where' => ["country_code='US'"], 'order_by' => 'name']);
    foreach ($marketIds as $marketId) {
        $market = new \Crave\Model\Market($marketId);
        if (!$market->country_code) {
            $market->country_code = 'us';
        }
        $market->url = strtolower("/" . $market->slug);
        $markets[] = $market;
    }
    mem($cache_name, $markets, '10 hours');
}
$panels = [];
$delimiter_index = ceil(count($markets) / 6);
$index = -1;
foreach ($markets as $market) {
    $panels[++$index / $delimiter_index][] = $market;
}
foreach ($panels as $panel) {
    ?>
		<ul id="place-list">
			<?php 
    foreach ($panel as $market) {
        ?>
			<li><a href="<?php 
        echo $market->url;
Example #5
0
<?php

//  gallery
global $dev, $is_dev;
$show_vf = $dev || $is_dev;
try {
    if (!$gallery) {
        if (!$_POST['_token']) {
            throw new Exception('AJAX request for a vFolder gallery requires a token');
        }
        $key = sprintf('vf_gallery:%s', $_POST['_token']);
        $get_params = function () use($key) {
            return mem($key);
        };
        // try to fetch mem_key 3 times
        for ($i = 0; $i < 3; $i++) {
            $params = $get_params();
            if ($params) {
                break;
            }
        }
        if (!$params) {
            $error = sprintf('Invalid gallery token: <strong>%s</strong>. Could not get params to generate gallery.', $_POST['_token']);
            throw new Exception($error);
        }
        $gallery = vf::gallery($params);
        $folder = $gallery->initFolder(true);
        $items = $folder->items;
    } else {
        $items = $gallery->folder->items;
        if (!$items) {
     $dbw_host = \Sky\Db::getPrimary($db);
     if (!$dbw_host) {
         // cannot determine master
         $db_error .= "db error ({$db_host}): cannot determine master \n";
         $dbw = NULL;
         break;
     }
     // we have determined the master, now we will connect to the master
     $dbw =& ADONewConnection($db_platform);
     @$dbw->Connect($dbw_host, $db_username, $db_password, $db_name);
     if ($dbw->ErrorMsg()) {
         // connection to the master failed, go into read-only
         $db_error .= "db error ({$dbw_host}): {$dbw->ErrorMsg()}, cannot connect to master \n";
         // the host we believe is the master is down
         // cache this so we don't try connecting to it again for a minute
         mem($dbw_status_key, 'true', $dbw_status_check_interval);
         $dbw = NULL;
         break;
     }
     // we connected successfully to the host we believe is the master
     // now we must verify this database actually is in fact the master
     // STONITH: it is guaranteed that only one host thinks it is the master
     $is_standby = \Sky\Db::isStandby($dbw);
     if ($is_standby) {
         // there is no master, or at least this standby doesn't know the
         // correct master.  this should only happen during a promotion.
         // go into read-only mode
         $dbw = NULL;
         break;
     }
 }
Example #7
0
File: seo.php Project: hshoghi/cms
<?php

$page_data = NULL;
global $seo_field_array;
global $website_id;
if (!$website_id) {
    $website_id = $p->vars['seo']['website']['website_id'];
}
if (!$website_id) {
    $website_id = $this->vars['website']->website_id;
}
if ($website_id) {
    //$mem_key = "seo:".$website_id.":".$p->page_path;
    $page_data = mem($mem_key);
    //		$page_data = NULL;
    if (!$page_data) {
        $rs = aql::select("website_page { url_specific where page_path = '{$p->page_path}' and website_id = {$website_id} }");
        if (is_numeric($rs[0]['website_page_id'])) {
            $pd = aql::select("website_page_data { field, value where website_page_id = {$rs[0]['website_page_id']} } ");
            if (is_array($pd)) {
                foreach ($pd as $data) {
                    $page_data[$data['field']] = $data['value'];
                }
                if ($rs[0]['url_specific'] == 1) {
                    $page_data['url_specific'] = true;
                }
                //mem($mem_key, $page_data);
            }
        }
    }
    if (is_array($page_data)) {
Example #8
0
    return call(compose(plus($x), plus($y)), $z) !== $x + $y + $z;
}, 'compose6' => function ($x, $y, $z) {
    return call(compose(flip('plus', $x), plus($y)), $z) !== $x + $y + $z;
}, 'compose7' => function ($x, $y, $z) {
    $f = flip('map', [$x, $y]);
    $c = compose($f, 'plus');
    return $c($z) !== [$x + $z, $y + $z];
}, 'compose8' => function ($x, $y) {
    $c = compose(with($x), 'plus');
    return $c($y) !== $x + $y;
}, 'sum' => function () {
    return sum($xs = range(0, mt_rand(1, 100))) !== array_reduce($xs, 'plus', 0);
}, 'random1' => function () {
    return !is_int(random(null));
}, 'mem1' => function () {
    return mem('true') <= 0;
}, 'upto1' => function ($n) {
    return count(upto($n % 100)) !== $n % 100;
}, 'between1' => function () {
    return between(5, 10) !== [5, 6, 7, 8, 9, 10];
}, 'b_then' => function ($n) {
    return branch(thunk($n), null, thunk(true), null) !== $n;
}, 'b_else' => function ($n) {
    return branch(null, thunk($n), thunk(false), null) !== $n;
}, 'until1' => function ($n) {
    $x = $n % 8;
    return until(function ($args) use($x) {
        list($m, $arr) = $args;
        return [$m === $x, [$m + 1, snoc($m, $arr)]];
    }, [0, []]) !== [$x + 1, upto($x + 1)];
}, 'trampoline1' => function ($n) {
Example #9
0
 /**
  * @param   string  $id
  * @return  \stdClass
  */
 public static function removeItem($id)
 {
     static::checkForClient();
     $item = static::getItem($id);
     $path = $item->folder;
     $folder = static::getFolder($path);
     // update the last upload time so we know when to refresh cached folders
     $memkey = "vf2:getFolder:lastUpload:" . $path;
     mem($memkey, date('U'));
     $memkey = "vf2:getFolder:lastUpload:" . $folder->id;
     mem($memkey, date('U'));
     return static::getClient()->deleteItem($id);
 }
Example #10
0
/**
* Getting dataset from cache, or run the function 
*/
function getFromCache($key, $func, $cache_time = 0)
{
    if ($cache_time === 0) {
        $cache_time = rand(10, 90);
    }
    $retval = $_GET['refresh'] ? null : \mem($key);
    if (!$retval) {
        $retval = $func();
        // d("FROM DB", $retval);
        \mem($key, $retval, "{$cache_time} minutes");
    }
    return $retval;
}
Example #11
0
<?php

global $website;
$event_id = 7852;
$key = 'cache:special-event:' . $event_id;
//$event = \mem($key);
$buy_url = 'https://secured.cravetickets.com/purchase/pXdEE7aA3vv/rquNesCME11/Bwfj5f5vP87?&r=newyears.com';
if (!$event) {
    $event = new \Crave\Model\ct_event($event_id);
    \mem($key, $event, '5 minutes');
}
$page->title = "";
$this->event = $event;
\Website::top($this);
?>

<link rel="stylesheet" href="<?php 
echo $this->template_url;
?>
content/vip-event.css" />
<section class="maincontent">	

<img style="width: 100%;" src="<?php 
echo $this->template_url;
?>
content\images\vip-event\W-Header.jpg" alt="<?php 
echo $event->event_name;
?>
" />

		
Example #12
0
	if (!$medias){ 
		$medias = $event->getVenuePhotos(['limit'=>10, 'width'=>600, 'height'=>400]);  


		if ($medias && count($medias)){
			foreach($medias as $key=>$media){

				if( is_object($media) ) {
					
					$media->thumb = \vf::getItem($media->id, $thumb_config);


				}
			}

			mem($cache_key, $medias, '20 minutes');
		} 



	}

	$event->medias = $medias; 


}


$right_events = getListingPage()->add_to_criteria(['market_id'=>decrypt($event->market->ide,'market')])->getSideEvents();

$announce_message = $event->getAnnounceMessage(); 
Example #13
0
            }
            // get medias
            $flyers = $ct_event->getFlyers(false, $media_config_small);
            if ($flyers['no_logo']) {
                $event->img_small = $flyers['no_logo'];
            } else {
                $mediaIds = $ct_event->getMediaIDs(1);
                $event->img_small = \vf::getItem($mediaIds[0], $media_config_small);
            }
            //$header_flyer = \vf::getItem($flyerId, $media_config_header_flyer);
            //$event->img_small = \vf::getItem($flyerId, $media_config_small);
            // $event->header_flyer_url = $header_flyer->src;
            $event->url = parseEventUrl($event);
            // include the template for event display.
            //include ('includes/events_listings_event.php');
            \mem($cache_event_key, $event, rand(2, 20) . ' minutes');
        }
        $events[] = $event;
        $event = null;
        //$obj = null ;
    }
    //		\mem($cache_name_events, $events , '20 minutes');
}
/** 
* @todo reorganize, and improve page's life cycle. too many loops for the same array.
*/
// build left rail filters
if ($events && count($events)) {
    foreach ($events as $event) {
        addItemToCounterArray($event_times, $event->event_time);
        addItemToCounterArray($nhoods, $event->where->neighborhood);
Example #14
0
 /**
  * Does the upload if there are no errors, and uploads the db_field if necessary
  * @return array   response array
  */
 public function doUpload()
 {
     if ($this->errors) {
         return $this->respond();
     }
     $upload_opts = array('folders_path' => $this->folders_path);
     $re = vf::$client->upload_to_server($this->uploaded_file, $upload_opts);
     unlink($this->uploaded_file);
     // delete file from tmpdir
     if (!$re['success']) {
         $this->errors[] = 'There was an error uploading the file:';
         $this->errors[] = $re['last_error'];
         return $this->respond($re);
     }
     // clear empty folder cache
     $key = vf::getEmptyFolderKey($this->folders_path);
     mem($key, null);
     if ($this->params['db_field'] && $this->params['db_row_id']) {
         $this->updateDBRecord($re['items_id']);
     }
     return $this->respond($re);
 }
 /**
  * Makes a fetcher function for the given key
  * @param   string      $key
  * @return  Function
  */
 private function _getFetchFn($key)
 {
     $check_mem = function ($key) {
         return aql2array::$aqlArrays[$key];
     };
     $fns = array('mem' => function () use($key, $check_mem) {
         return $check_mem($key) ?: mem($key);
     }, 'disk' => function () use($key, $check_mem) {
         return $check_mem($key) ?: unserialize(disk($key));
     });
     if (!array_key_exists(self::$mem_type, $fns)) {
         throw new Exception('Invalid mem type.');
     }
     return $fns[self::$mem_type];
 }
Example #16
0
 /**
  *	stores object variables in memcache
  */
 public function setMemToken()
 {
     $vars = get_object_vars($this);
     $this->_token = md5(serialize($vars));
     mem($this->getMemKey($this->_token), $vars);
 }
Example #17
0
            $event->venue->zip = $event->zip;
            $event->venue->state = $event->state;
            $event->url = parseEventUrl($event);
            $ct_event->ct_event_id = $event->ct_event_id;
            /**
             * Fetch media for the event .
             */
            $mediaIds = $ct_event->getMediaIDs(1);
            $index = count($mediaIds) > 1 ? 1 : 0;
            //$mediaIds[$index]
            $event->img_small = \vf::getItem($ct_event->getFlyer(), $media_config_small);
            if (!$event->img_small && count($mediaIds)) {
                $event->img_small = \vf::getItem($mediaIds[0], $media_config_small);
            }
        });
        \mem($cache_name, $events, $event_cache_duration);
    }
    $default_markets[$i]['events'] = $events;
}
\Website::top();
?>
			<section class="banner slider">

			<?php 
include "templates/website/media-box/mediabox.php";
?>
			
	</section>

<div>
Example #18
0
 /**
  * Does the upload if there are no errors, and uploads the db_field if necessary
  * @return array   response array
  */
 public function doUpload()
 {
     if ($this->errors) {
         return $this->respond();
     }
     $upload_opts = array('folder' => $this->folders_path);
     $re = Client::getClient()->addItem($upload_opts, $this->uploaded_file);
     unlink($this->uploaded_file);
     // delete file from tmpdir
     if ($re->errors) {
         $this->errors[] = 'There was an error uploading the file:';
         $this->errors = array_merge($this->errors, array_map(function ($e) {
             return $e->message;
         }, $re->errors));
         return $this->respond($re);
     }
     if ($this->params['db_field'] && $this->params['db_row_id']) {
         $this->updateDBRecord($re->item->id);
     }
     $folder = Client::getFolder($this->folders_path);
     // update the last upload time so we know when to refresh cached folders
     $memkey = "vf2:getFolder:lastUpload:" . $this->folders_path;
     mem($memkey, date('U'));
     $memkey = "vf2:getFolder:lastUpload:" . $folder->id;
     mem($memkey, date('U'));
     return $this->respond($re);
 }
 /**
  * Attempts to fetch data from cache, sets the object,
  * otherwise, reads from db, sets the object and cache
  *
  * @param  mixed $id                   identifier(id, ide)
  * @param  Boolean $force_db           force db read, default: false
  * @param  Boolean $use_dbw            force master db read, default: false
  * @return Model   $this
  * @throws InvalidArgumentException    invalid identifier
  * @throws ModelNotFoundException      when object not found
  * @throws LogicException              if cannot generate cache key
  */
 public function loadDB($id, $force_db = false, $use_dbw = false)
 {
     #elapsed("loadDB(".$id.")");
     $id = !is_numeric($id) ? decrypt($id, $this->getPrimaryTable()) : $id;
     if (!$id) {
         throw new InvalidArgumentException('Invalid Identifier passed to loadDB()');
     }
     $mem_key = $this->getMemKey($id);
     if (!$mem_key) {
         throw new LogicException('Could not generate cache key.');
     }
     # exit early if load will fail
     if ($this->_errors) {
         return $this;
     }
     # set booleans
     $reload_subs = false;
     $force_db = $force_db || $this->_force_db || $_GET['refresh'] ? true : false;
     $is_subclass = $this->_model_name != 'Model';
     # if reloading from DB, make sure we're doing it form Master, not slave.
     if ($force_db || $use_dbw) {
         $use_dbw = true;
         $dbw = $this->getMasterDB();
     }
     $conn = $use_dbw ? $dbw : null;
     # for lexical binding with anonymous funcitons.
     $that = $this;
     # function that reads and sets data
     $load = function ($mem_key = null) use($that, $conn, $id) {
         $o = aql::profile($that->getModelName(), $id, true, $that->_aql, true, $conn);
         if ($mem_key) {
             $o->_cached_time = date('c');
             \Sky\Memcache::set($mem_key, $o);
         }
         return $o;
     };
     if (!$force_db && $is_subclass) {
         #elapsed('get ' . $this->_model_name . ' model object from cache');
         $o = mem($mem_key);
         # do a normal get from cache
         if (!$o->_data || self::cacheExpired($o)) {
             $o = $load($mem_key);
             # if cache not found or expired, load from DB
         } else {
             #elapsed('we will be reloading subs');
             $reload_subs = true;
             # we will be reloading submodels
         }
     } elseif ($force_db && $is_subclass && !$this->_aql_set_in_constructor) {
         $o = $load($mem_key);
         # refresh was specified
     } else {
         $o = $load();
         # this is a temp model, fetch from db
     }
     if (self::isModelClass($o) && is_array($o->_data)) {
         # we have a proper object fetched, update the data in $this using $o
         $arr = array('data', 'properties', 'objects');
         array_walk($arr, function ($key) use($o, $that) {
             $k = '_' . $key;
             $that->{$k} = array_merge($that->{$k}, $o->{$k});
         });
         $this->_id = $id;
         $this->_cached_time = $o->_cached_time;
         if ($reload_subs) {
             #elapsed('$this->reloadSubs()');
             $this->reloadSubs($use_dbw);
         }
     } else {
         # throw new ModelNotFoundException; # some time in the future
         $this->addInternalError('no_data_found');
     }
     return $this;
 }
Example #20
0
 public function cancelMailList($list_id, $user_id)
 {
     $cancelsql = "UPDATE `mail_user_list`\n\t\t\t\t\t\t   SET `user_isdelete`=1\n\t\t\t\t\t\t   WHERE `user_list_id`='{$list_id}'\n\t\t\t\t\t\t   AND `user_name_id` = '{$user_id}'";
     $result = $this->dbconn->query($cancelsql);
     //更新memcache
     $memret = checkPower($list_id);
     mem($memname, $memret);
     return $result;
 }
function processXmls(&$p_aUrls, $p_aXmls, $p_iGZIP, $p_sListingTagName, $p_sUrlTagName, $p_sTerritory, $p_sSection, $p_sSourceID, &$total_in_xmls)
{
    $total_in_xmls = 0;
    foreach ($p_aXmls as $l_sXml) {
        if ($l_sXml == 'http://api.ilsa.ru/sale/v1/dealers.xml') {
            $newfile = substr($l_sXml, strrpos($l_sXml, '/') + 1);
            $linkToXmlFile = "compress.zlib://" . $newfile;
            $xml = new XMLReader();
            $xml->open($linkToXmlFile);
            $readSuccess = TRUE;
            $readOuterSuccess = TRUE;
            $l_aXmls = array();
            while ($readSuccess) {
                $readSuccess = $xml->read();
                if ($readSuccess && $xml->name == "Dealer" && $xml->nodeType == XMLReader::ELEMENT) {
                    $tmp = $xml->readOuterXML();
                    $l_oDealer = simplexml_load_string($tmp);
                    if (isset($l_oDealer->Offers->Link)) {
                        $l_aXmls[] = trim($l_oDealer->Offers->Link);
                    }
                } else {
                    //print "\n\$readSuccess = ".$readSuccess.". \$xml->name = ".$xml->name.". \$xml->nodeType = ".$xml->nodeType;
                }
            }
            $local_file = 'autoi.xml';
            $linkToXmlFile = $local_file;
            foreach ($l_aXmls as $dealer) {
                print "\n" . date("d/m/y : H:i:s", time()) . " pid: " . getmypid() . " parsing: " . $dealer;
                $access_key = "YzQ2OTg1MWQ2YWU1Y2MwMGZlYTc5MzQ5YTliMGY4OWZlNWVjOGRmOGQ2M2EyNjFkY2MxMDcwMGYyMmQ3NTdhNg";
                $curl = curl_init($dealer);
                curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $access_key));
                curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                $source = curl_exec($curl);
                curl_close($curl);
                if ($source === FALSE) {
                    print "\n" . date("d/m/y : H:i:s", time()) . " pid: " . getmypid() . " failed to copy {$dealer}...";
                    sleep(5);
                } else {
                    $fp = fopen($local_file, 'w');
                    fwrite($fp, $source);
                    fclose($fp);
                    $xml = new XMLReader();
                    $xml->open($linkToXmlFile);
                    $readSuccess = TRUE;
                    $readOuterSuccess = TRUE;
                    while ($readSuccess) {
                        $readSuccess = $xml->read();
                        if ($readSuccess && $xml->name == "Vehicle" && $xml->nodeType == XMLReader::ELEMENT) {
                            $total_in_xmls++;
                            $tmp = $xml->readOuterXML();
                            $l_oListing = simplexml_load_string($tmp);
                            $url = $l_oListing->attributes()->Id;
                            $url = 'http://auto.ilsa.ru/car/' . $url;
                            if (isset($p_aUrls[$url])) {
                                unset($p_aUrls[$url]);
                            }
                            unset($l_oListing);
                        } else {
                            //print "\n\$readSuccess = ".$readSuccess.". \$xml->name = ".$xml->name.". \$xml->nodeType = ".$xml->nodeType;
                        }
                    }
                    unset($xml);
                }
            }
        } else {
            if ($l_sXml == 'http://xml.jcat.ru/export/pingola/realty-vip/') {
                $newfile = 'jcat_realty_vip.xml';
            } elseif ($l_sXml == 'http://xml.jcat.ru/export/pingola/cars-vip/') {
                $newfile = 'jcat_cars_vip.xml';
            } elseif ($l_sXml == 'http://xml.jcat.ru/export/pingola/jobs-vip/') {
                $newfile = 'jcat_jobs_vip.xml';
            } elseif ($l_sXml == 'http://xml.jcat.ru/export/pingola/realty/') {
                $newfile = 'jcat_realty.xml';
            } elseif ($l_sXml == 'http://xml.jcat.ru/export/pingola/cars/') {
                $newfile = 'jcat_cars.xml';
            } elseif ($l_sXml == 'http://xml.jcat.ru/export/pingola/jobs/') {
                $newfile = 'jcat_jobs.xml';
            } elseif ($l_sXml == 'http://arenda-kvartir.ndv.ru/flib/xml_pingola.php') {
                $newfile = 'xml_pingola_rent.xml';
            } elseif ($l_sXml == 'http://www.trucksale.ru/cron/export-pingola/') {
                $newfile = 'trucksale.xml';
            } elseif ($l_sXml == 'http://www.mjobs.ru/rss/yvlAll/') {
                $newfile = 'mjobs.xml';
            } elseif ($l_sXml == 'http://110km.ru/871230y231/') {
                $newfile = '110km.xml';
            } else {
                $newfile = substr($l_sXml, strrpos($l_sXml, '/') + 1);
            }
            printer("Reading " . $newfile);
            if ($p_iGZIP) {
                $linkToXmlFile = "compress.zlib://" . $newfile;
            } else {
                $linkToXmlFile = $newfile;
            }
            $xml = new XMLReader();
            $xml->open($linkToXmlFile);
            $readSuccess = TRUE;
            while ($readSuccess) {
                $readSuccess = $xml->read();
                if ($xml->name == $p_sListingTagName && $xml->nodeType == XMLReader::ELEMENT) {
                    $total_in_xmls++;
                    $tmp = $xml->readOuterXML();
                    $l_oListing = simplexml_load_string($tmp);
                    $url = trim($l_oListing->{$p_sUrlTagName});
                    if ($p_sTerritory == 'ru' && $p_sSection == 'vehicles' && $p_sSourceID == '224') {
                        $url = substr($url, strrpos($url, '/') + 1);
                    } elseif ($p_sTerritory == 'ru' && $p_sSection == 'vehicles' && $p_sSourceID == '382') {
                        if (strpos($url, 'http://') === FALSE) {
                            $url = 'http://' . $url;
                        }
                    } elseif ($p_sTerritory == 'ru' && $p_sSection == 'realestate' && $p_sSourceID == '5597') {
                        if (strpos($url, 'http://') === FALSE) {
                            $url = 'http://' . $url;
                        }
                    } elseif ($p_sTerritory == 'ru' && $p_sSection == 'jobs' && $p_sSourceID == '5637') {
                        if (strpos($url, 'http://') === FALSE) {
                            $url = 'http://' . $url;
                        }
                    } elseif ($p_sTerritory == 'ru' && $p_sSection == 'vehicles' && $p_sSourceID == '404') {
                        $url = str_replace('http://automobile.ru/', 'http://www.automobile.ru/', $url);
                        if (strpos($url, '?utm') !== FALSE) {
                            $url = str_replace('?utm', '/?utm', $url);
                        }
                    } elseif ($p_sTerritory == 'ru' && $p_sSection == 'vehicles' && strpos($l_sXml, 'ftp://carcopy.ru/') !== FALSE) {
                        $url = 'http://zaavto.ru/search/car/detail.php?id_vehicle=' . $url;
                    } elseif ($p_sTerritory == 'ru' && $p_sSection == 'vehicles' && $p_sSourceID == '1364') {
                        if (strpos($url, '?') !== FALSE) {
                            $url = substr($url, 0, strpos($url, '?'));
                        }
                    } elseif ($p_sTerritory == 'ru' && $p_sSection == 'realestate' && $p_sSourceID == '1189') {
                        if (strpos($url, '&') !== FALSE) {
                            $url = substr($url, 0, strpos($url, '&'));
                        }
                    } elseif ($p_sTerritory == 'ru' && $p_sSection == 'realestate' && $p_sSourceID == '2387') {
                        $url = str_replace('http://domus-finance.ru/', 'http://www.domus-finance.ru/', $url);
                    } elseif ($p_sTerritory == 'ru' && $p_sSection == 'realestate' && $p_sSourceID == '1369') {
                        if (strpos($url, '#') !== FALSE) {
                            $url = substr($url, 0, strpos($url, '#'));
                        }
                        if (strpos($url, '?') !== FALSE) {
                            $url = substr($url, 0, strpos($url, '?'));
                        }
                        if (strpos($url, '-') !== FALSE) {
                            $url = substr($url, strrpos($url, '-') + 1);
                        } else {
                            $url = substr($url, strrpos($url, '/', -5) + 1);
                        }
                    } elseif ($p_sTerritory == 'ru' && $p_sSection == 'realestate' && $p_sSourceID == '1577') {
                        if (strpos($url, '#') !== FALSE) {
                            $url = substr($url, 0, strpos($url, '#'));
                        }
                    } elseif ($p_sTerritory == 'ru' && $p_sSection == 'realestate' && $p_sSourceID == '188') {
                        if (strpos($url, '#') !== FALSE) {
                            $url = substr($url, 0, strpos($url, '#'));
                        }
                        $url = str_replace('http://realestate.ru/', 'http://www.realestate.ru/', $url);
                    } elseif ($p_sTerritory == 'ru' && $p_sSection == 'realestate' && $p_sSourceID == '4587') {
                        $url = str_replace('http://http://', 'http://', $url);
                    } elseif ($p_sTerritory == 'ru' && $p_sSection == 'jobs' && $p_sSourceID == '290') {
                        $url = substr($url, strpos($url, '/vacancy') + strlen('/vacancy'));
                        if (strpos($url, '-') !== FALSE) {
                            $url = substr($url, 0, strpos($url, '-'));
                        } else {
                            $url = substr($url, 0, strpos($url, '.html'));
                        }
                    } elseif ($p_sTerritory == 'ru' && $p_sSection == 'jobs' && $p_sSourceID == '197') {
                        if (strpos($url, '?') !== FALSE) {
                            $url = substr($url, 0, strpos($url, '?'));
                        }
                    } elseif ($p_sTerritory == 'ru' && $p_sSection == 'realestate' && $p_sSourceID == '1394') {
                        if (strpos($url, '?') !== FALSE) {
                            $url = substr($url, 0, strpos($url, '?'));
                        }
                    } elseif ($p_sTerritory == 'ru' && $p_sSection == 'vehicles' && ($p_sSourceID == '96' || $p_sSourceID == '1709')) {
                        if (strpos($url, '?') !== FALSE) {
                            $url = substr($url, 0, strpos($url, '?'));
                        }
                    } elseif ($p_sTerritory == 'ru' && $p_sSection == 'realestate' && $p_sSourceID == '5474') {
                        $tmp = 'internal-id';
                        $url = 'http://soft-estate.ru/announcements/view?id=' . trim($l_oListing->attributes()->{$tmp});
                    }
                    if (isset($p_aUrls[$url])) {
                        unset($p_aUrls[$url]);
                    }
                }
            }
            unset($xml);
            mem();
        }
    }
}
Example #22
0
 public static function getRandomItems($folders_id = NULL, $limit = NULL, $width = NULL, $height = NULL, $crop = NULL)
 {
     $request_array = array('random' => true, 'limit' => $limit ? $limit : 10);
     if (is_array($limit)) {
         $request_array = $limit;
         $request_array['random'] || ($request_array['random'] = true);
     } else {
         if (is_array($width)) {
             $request_array['operations'] = $width;
         } else {
             if ($width) {
                 $operations = array();
                 $operations[] = array('type' => $crop ? 'smart_crop' : 'resize', 'height' => $height, 'width' => $width);
                 $crop && ($operations[0]['gravity'] = $crop !== true ? $crop : 'Center');
                 $request_array['operations'] = $operations;
             }
         }
     }
     $mem_key = 'getRandomItems:' . $folders_id . ':' . md5(serialize($request_array));
     $no_items_value = 'no items';
     $items = mem($mem_key);
     if (!$items) {
         $folder = self::$client->get_folder($folders_id, $request_array);
         $items = $folder['items'];
         if (!$items) {
             $items = $no_items_value;
         }
         mem($mem_key, $items, '1 day');
     }
     if ($items == $no_items_value) {
         $items = null;
     }
     return $items;
 }