Beispiel #1
0
 public static function cleanOld()
 {
     $urls = \CMF\Model\URL::select('item')->getQuery()->getResult();
     $deleted = 0;
     foreach ($urls as $url) {
         $item = $url->item();
         if (empty($item)) {
             \D::manager()->remove($url);
             $deleted++;
         }
     }
     \D::manager()->flush();
     return $deleted;
 }
Beispiel #2
0
 /**
  * Given the value of a link object field (external or internal), will return the correct url
  * @param object $data
  * @return string
  */
 public static function getLink($data)
 {
     // Get the link attribute
     if ($is_array = is_array($data)) {
         $output = isset($data['href']) ? $data['href'] : '';
     } else {
         $output = strval($data);
     }
     // Internal links
     if (substr($output, 0, 1) == '/' && strpos($output, '//') !== 0) {
         return \Uri::create($output);
     }
     // Empty links or anchor links
     if (empty($output) || substr($output, 0, 1) == '#') {
         return $output;
     }
     // Query the urls table if it's an ID
     if (is_numeric($output)) {
         $link = \CMF\Model\URL::select('item.url')->where('item.id = ' . $output)->getQuery();
         // Set the query hint if multi lingual!
         if (\CMF\Doctrine\Extensions\Translatable::enabled()) {
             $link->setHint(\Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker');
         }
         $link = $link->getArrayResult();
         $output = count($link) > 0 ? static::link($link[0]['url']) : null;
     } else {
         if (strpos($output, 'http') !== 0 && strpos($output, '//') !== 0) {
             $output = "http://" . $output;
         }
     }
     return strval($output);
 }
Beispiel #3
0
 public static function processLink($data)
 {
     // Get the link attribute
     if ($is_array = is_array($data)) {
         $output = isset($data['href']) ? $data['href'] : '';
     } else {
         $output = $data;
     }
     // Query the urls table if it's an ID
     if (is_numeric($output)) {
         $link = \CMF\Model\URL::select('item.url')->where('item.id = ' . $output)->getQuery()->getScalarResult();
         $output = count($link) > 0 ? $link[0]['url'] : null;
     }
     // Return the same array that was passed in...
     if ($is_array) {
         $data['href'] = $output;
         return $data;
     }
     return array('href' => $output);
 }